New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify cli input parsing #549
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use std::process::Command; | ||
|
||
fn main() { | ||
let output = Command::new("git").args(&["rev-parse", "HEAD"]).output().unwrap(); | ||
let git_hash = String::from_utf8(output.stdout).unwrap(); | ||
println!("cargo:rustc-env=GIT_HASH={}", git_hash); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,18 +3,18 @@ use colored::Colorize; | |
use structopt::*; | ||
|
||
#[derive(StructOpt)] | ||
#[structopt(version = env!("GIT_HASH"))] | ||
enum Command { | ||
/// Apply a prisma schema to a database | ||
#[structopt(name = "apply-schema")] | ||
ApplySchema { | ||
/// The path to the prisma schema file. Either this or --stdin should be provided. | ||
#[structopt(long = "file-path")] | ||
#[structopt(long)] | ||
file_path: Option<String>, | ||
/// Try to read the prisma schema from stdin. Either this or --file-path should be provided. | ||
#[structopt(long = "stdin")] | ||
#[structopt(long)] | ||
stdin: bool, | ||
/// Whether to ignore warnings from the migration engine regarding data loss. Default: false. | ||
#[structopt(long = "force")] | ||
#[structopt(long)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't know that either, great! |
||
force: Option<bool>, | ||
}, | ||
} | ||
|
@@ -58,7 +58,6 @@ fn main() -> anyhow::Result<()> { | |
}; | ||
|
||
let result = api.apply_migration(&apply_input).await?; | ||
|
||
let warnings = result.warnings.into_iter().map(|warning| warning.description).collect(); | ||
|
||
Ok::<Vec<String>, anyhow::Error>(warnings) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use datamodel::ast::reformat::Reformatter; | ||
use std::{ | ||
fs::{self, File}, | ||
io::{self, BufWriter, Read}, | ||
}; | ||
|
||
use crate::FormatOpts; | ||
|
||
pub fn run(opts: FormatOpts) { | ||
let datamodel_string = match opts.input { | ||
Some(file_name) => { | ||
fs::read_to_string(&file_name).expect(&format!("Unable to open file {}", file_name.display())) | ||
} | ||
None => { | ||
let mut buf = String::new(); | ||
|
||
io::stdin() | ||
.read_to_string(&mut buf) | ||
.expect("Unable to read from stdin."); | ||
|
||
buf | ||
} | ||
}; | ||
|
||
match opts.output { | ||
Some(file_name) => { | ||
let file = File::open(&file_name).expect(&format!("Unable to open file {}", file_name.display())); | ||
let mut stream = BufWriter::new(file); | ||
|
||
Reformatter::reformat_to(&datamodel_string, &mut stream, opts.tabwidth); | ||
} | ||
None => { | ||
Reformatter::reformat_to(&datamodel_string, &mut io::stdout().lock(), opts.tabwidth); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh I didn't know that option, it's great!