difftreelog
fix workaround ugly generate command
in: master
1 file changed
cmds/jrsonnet/src/main.rsdiffbeforeafterboth1use std::{1use std::{2 env::current_dir,2 fs::{create_dir_all, File},3 fs::{create_dir_all, File},3 io::{Read, Write},4 io::{Read, Write},4 path::PathBuf,5};5};667use clap::{AppSettings, IntoApp, Parser};7use clap::{AppSettings, IntoApp, Parser};8use clap_complete::Shell;8use clap_complete::Shell;9use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};9use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, ManifestOpts, OutputOpts};10use jrsonnet_evaluator::{error::LocError, State};10use jrsonnet_evaluator::{error::LocError, State};111112#[cfg(feature = "mimalloc")]12#[cfg(feature = "mimalloc")]31 pub os_stack: Option<usize>,31 pub os_stack: Option<usize>,32}32}3334#[derive(Parser)]35#[clap(next_help_heading = "INPUT")]36struct InputOpts {37 /// Treat input as code, evaluate them instead of reading file38 #[clap(long, short = 'e')]39 pub exec: bool,4041 /// Path to the file to be compiled if `--evaluate` is unset, otherwise code itself42 pub input: Option<String>,43}334434#[derive(Parser)]45#[derive(Parser)]35#[clap(46#[clap(36 global_setting = AppSettings::DeriveDisplayOrder,47 global_setting = AppSettings::DeriveDisplayOrder,37 // args_conflicts_with_subcommands = true,48 args_conflicts_with_subcommands = true,38)]49)]39struct Opts {50struct Opts {40 #[clap(subcommand)]51 #[clap(subcommand)]93 Io(#[from] std::io::Error),104 Io(#[from] std::io::Error),94 #[error("input is not utf8 encoded")]105 #[error("input is not utf8 encoded")]95 Utf8(#[from] std::str::Utf8Error),106 Utf8(#[from] std::str::Utf8Error),107 #[error("missing input argument")]108 MissingInputArgument,96}109}97impl From<LocError> for Error {110impl From<LocError> for Error {98 fn from(e: LocError) -> Self {111 fn from(e: LocError) -> Self {118 opts.general.configure(s)?;131 opts.general.configure(s)?;119 opts.manifest.configure(s)?;132 opts.manifest.configure(s)?;120133134 let input = opts.input.input.ok_or(Error::MissingInputArgument)?;121 let val = if opts.input.exec {135 let val = if opts.input.exec {122 s.evaluate_snippet("<cmdline>".to_owned(), (&opts.input.input as &str).into())?136 s.evaluate_snippet("<cmdline>".to_owned(), (&input as &str).into())?123 } else if opts.input.input == "-" {137 } else if input == "-" {124 let mut input = Vec::new();138 let mut input = Vec::new();125 std::io::stdin().read_to_end(&mut input)?;139 std::io::stdin().read_to_end(&mut input)?;126 let input_str = std::str::from_utf8(&input)?.into();140 let input_str = std::str::from_utf8(&input)?.into();127 s.evaluate_snippet("<stdin>".to_owned(), input_str)?141 s.evaluate_snippet("<stdin>".to_owned(), input_str)?128 } else {142 } else {129 s.import(s.resolve_file(&PathBuf::new(), &opts.input.input)?)?143 s.import(s.resolve_file(¤t_dir().expect("cwd"), &input)?)?130 };144 };131145132 let val = s.with_tla(val)?;146 let val = s.with_tla(val)?;