git.delta.rocks / jrsonnet / refs/commits / 9efbcad25b9d

difftreelog

build upgrade clap to v3.1

Yaroslav Bolyukin2022-03-06parent: #4ec6326.patch.diff
in: master

8 files changed

modifiedcmds/jrsonnet/Cargo.tomldiffbeforeafterboth
18mimallocator = { version = "0.1.3", optional = true }18mimallocator = { version = "0.1.3", optional = true }
19thiserror = "1.0"19thiserror = "1.0"
20gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }20gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
2121clap = { version = "3.1", features = ["derive"] }
22[dependencies.clap]22clap_complete = { version = "3.1" }
23git = "https://github.com/clap-rs/clap"
24rev = "f0c5ea5e1503de5c8e74d8c047a799cf51498e83"
25
26[dependencies.clap_generate]
27git = "https://github.com/clap-rs/clap"
28rev = "f0c5ea5e1503de5c8e74d8c047a799cf51498e83"
2923
modifiedcmds/jrsonnet/src/main.rsdiffbeforeafterboth
1use clap::{AppSettings, Clap, IntoApp};1use clap::{AppSettings, IntoApp, Parser};
2use clap_complete::Shell;
2use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};3use jrsonnet_cli::{ConfigureState, GcOpts, GeneralOpts, InputOpts, ManifestOpts, OutputOpts};
3use jrsonnet_evaluator::{error::LocError, EvaluationState};4use jrsonnet_evaluator::{error::LocError, EvaluationState};
4use std::{5use std::{
5 fs::{create_dir_all, File},6 fs::{create_dir_all, File},
6 io::Read,7 io::Read,
7 io::Write,8 io::Write,
8 path::PathBuf,9 path::PathBuf,
9 str::FromStr,
10};10};
1111
12#[cfg(feature = "mimalloc")]12#[cfg(feature = "mimalloc")]
13#[global_allocator]13#[global_allocator]
14static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;14static GLOBAL: mimallocator::Mimalloc = mimallocator::Mimalloc;
15
16#[derive(Parser)]
17enum SubOpts {
18 /// Generate completions for specified shell
19 Generate {
20 /// Target shell name
21 shell: Shell,
22 },
23}
1524
16#[derive(Clap)]25#[derive(Parser)]
17#[clap(help_heading = "DEBUG")]26#[clap(next_help_heading = "DEBUG")]
18struct DebugOpts {27struct DebugOpts {
19 /// Required OS stack size.28 /// Required OS stack size.
20 /// This shouldn't be changed unless jrsonnet is failing with stack overflow error.29 /// This shouldn't be changed unless jrsonnet is failing with stack overflow error.
21 #[clap(long, name = "size")]30 #[clap(long, name = "size")]
22 pub os_stack: Option<usize>,31 pub os_stack: Option<usize>,
23 /// Generate completions script
24 #[clap(long)]
25 generate: Option<GenerateTarget>,
26}32}
27
28enum GenerateTarget {
29 Bash,
30 Zsh,
31 Fish,
32 PowerShell,
33}
34impl FromStr for GenerateTarget {
35 type Err = &'static str;
36
37 fn from_str(s: &str) -> Result<Self, Self::Err> {
38 match s {
39 "bash" => Ok(Self::Bash),
40 "zsh" => Ok(Self::Zsh),
41 "fish" => Ok(Self::Fish),
42 "powershell" => Ok(Self::PowerShell),
43 _ => Err("unknown target"),
44 }
45 }
46}
4733
48#[derive(Clap)]34#[derive(Parser)]
49#[clap(35#[clap(
50 global_setting = AppSettings::ColoredHelp,36 global_setting = AppSettings::DeriveDisplayOrder,
51 global_setting = AppSettings::DeriveDisplayOrder,37 // args_conflicts_with_subcommands = true,
52)]38)]
53struct Opts {39struct Opts {
40 #[clap(subcommand)]
41 sub: Option<SubOpts>,
42
54 #[clap(flatten)]43 #[clap(flatten)]
55 input: InputOpts,44 input: InputOpts,
68fn main() {57fn main() {
69 let opts: Opts = Opts::parse();58 let opts: Opts = Opts::parse();
7059
71 if let Some(target) = opts.debug.generate {60 if let Some(sub) = opts.sub {
72 use clap_generate::{generate, generators};61 match sub {
73 use GenerateTarget::*;62 SubOpts::Generate { shell } => {
63 use clap_complete::generate;
74 let app = &mut Opts::into_app();64 let app = &mut Opts::command();
75 let buf = &mut std::io::stdout();65 let buf = &mut std::io::stdout();
76 let bin = "jrsonnet";
77 match target {
78 Bash => generate::<generators::Bash, _>(app, bin, buf),
79 Zsh => generate::<generators::Zsh, _>(app, bin, buf),
80 Fish => generate::<generators::Fish, _>(app, bin, buf),
81 PowerShell => generate::<generators::PowerShell, _>(app, bin, buf),66 generate(shell, app, "jrsonnet", buf);
82 }
83 std::process::exit(0);67 std::process::exit(0)
68 }
69 }
84 };70 }
8571
86 let success = if let Some(size) = opts.debug.os_stack {72 let success = if let Some(size) = opts.debug.os_stack {
87 std::thread::Builder::new()73 std::thread::Builder::new()
modifiedcrates/jrsonnet-cli/Cargo.tomldiffbeforeafterboth
14jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }14jrsonnet-parser = { path = "../../crates/jrsonnet-parser", version = "0.4.2" }
15gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }15gcmodule = { git = "https://github.com/CertainLach/gcmodule", branch = "jrsonnet" }
1616
17[dependencies.clap]17clap = { version = "3.1", features = ["derive"] }
18git = "https://github.com/clap-rs/clap"
19rev = "f0c5ea5e1503de5c8e74d8c047a799cf51498e83"
2018
modifiedcrates/jrsonnet-cli/src/ext.rsdiffbeforeafterboth
1use crate::ConfigureState;1use crate::ConfigureState;
2use clap::Clap;2use clap::Parser;
3use jrsonnet_evaluator::{error::Result, EvaluationState};3use jrsonnet_evaluator::{error::Result, EvaluationState};
4use std::{fs::read_to_string, str::FromStr};4use std::{fs::read_to_string, str::FromStr};
55
53 }53 }
54}54}
5555
56#[derive(Clap)]56#[derive(Parser)]
57#[clap(help_heading = "EXTERNAL VARIABLES")]57#[clap(next_help_heading = "EXTERNAL VARIABLES")]
58pub struct ExtVarOpts {58pub struct ExtVarOpts {
59 /// Add string external variable.59 /// Add string external variable.
60 /// External variables are globally available so it is preferred60 /// External variables are globally available so it is preferred
modifiedcrates/jrsonnet-cli/src/lib.rsdiffbeforeafterboth
8pub use tla::*;8pub use tla::*;
9pub use trace::*;9pub use trace::*;
1010
11use clap::Clap;11use clap::Parser;
12use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};12use jrsonnet_evaluator::{error::Result, EvaluationState, FileImportResolver};
13use std::{env, path::PathBuf};13use std::{env, path::PathBuf};
1414
15pub trait ConfigureState {15pub trait ConfigureState {
16 fn configure(&self, state: &EvaluationState) -> Result<()>;16 fn configure(&self, state: &EvaluationState) -> Result<()>;
17}17}
1818
19#[derive(Clap)]19#[derive(Parser)]
20#[clap(help_heading = "INPUT")]20#[clap(next_help_heading = "INPUT")]
21pub struct InputOpts {21pub struct InputOpts {
22 /// Treat input as code, evaluate them instead of reading file
22 #[clap(23 #[clap(long, short = 'e')]
23 long,
24 short = 'e',
25 about = "Treat input as code, evaluate them instead of reading file"
26 )]
27 pub exec: bool,24 pub exec: bool,
2825
29 #[clap(26 /// Path to the file to be compiled if `--evaluate` is unset, otherwise code itself
30 about = "Path to the file to be compiled if `--evaluate` is unset, otherwise code itself"
31 )]
32 pub input: String,27 pub input: String,
33}28}
3429
35#[derive(Clap)]30#[derive(Parser)]
36#[clap(help_heading = "OPTIONS")]31#[clap(next_help_heading = "OPTIONS")]
37pub struct MiscOpts {32pub struct MiscOpts {
38 /// Disable standard library.33 /// Disable standard library.
39 /// By default standard library will be available via global `std` variable.34 /// By default standard library will be available via global `std` variable.
74}69}
7570
76/// General configuration of jsonnet71/// General configuration of jsonnet
77#[derive(Clap)]72#[derive(Parser)]
78#[clap(name = "jrsonnet", version, author)]73#[clap(name = "jrsonnet", version, author)]
79pub struct GeneralOpts {74pub struct GeneralOpts {
80 #[clap(flatten)]75 #[clap(flatten)]
100 }95 }
101}96}
10297
103#[derive(Clap)]98#[derive(Parser)]
104#[clap(help_heading = "GARBAGE COLLECTION")]99#[clap(next_help_heading = "GARBAGE COLLECTION")]
105pub struct GcOpts {100pub struct GcOpts {
106 /// Do not skip gc on exit101 /// Do not skip gc on exit
107 #[clap(long)]102 #[clap(long)]
modifiedcrates/jrsonnet-cli/src/manifest.rsdiffbeforeafterboth
1use crate::ConfigureState;1use crate::ConfigureState;
2use clap::Clap;2use clap::Parser;
3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};3use jrsonnet_evaluator::{error::Result, EvaluationState, ManifestFormat};
4use std::{path::PathBuf, str::FromStr};4use std::{path::PathBuf, str::FromStr};
55
22 }22 }
23}23}
2424
25#[derive(Clap)]25#[derive(Parser)]
26#[clap(help_heading = "MANIFESTIFICATION OUTPUT")]26#[clap(next_help_heading = "MANIFESTIFICATION OUTPUT")]
27pub struct ManifestOpts {27pub struct ManifestOpts {
28 /// Output format, wraps resulting value to corresponding std.manifest call.28 /// Output format, wraps resulting value to corresponding std.manifest call.
29 /// If set to `string` then plain string value is expected to be returned,29 /// If set to `string` then plain string value is expected to be returned,
66 }66 }
67}67}
6868
69#[derive(Clap)]69#[derive(Parser)]
70pub struct OutputOpts {70pub struct OutputOpts {
71 /// Write to the output file rather than stdout71 /// Write to the output file rather than stdout
72 #[clap(long, short = 'o')]72 #[clap(long, short = 'o')]
modifiedcrates/jrsonnet-cli/src/tla.rsdiffbeforeafterboth
1use crate::{ConfigureState, ExtFile, ExtStr};1use crate::{ConfigureState, ExtFile, ExtStr};
2use clap::Clap;2use clap::Parser;
3use jrsonnet_evaluator::{error::Result, EvaluationState};3use jrsonnet_evaluator::{error::Result, EvaluationState};
44
5#[derive(Clap)]5#[derive(Parser)]
6#[clap(help_heading = "TOP LEVEL ARGUMENTS")]6#[clap(next_help_heading = "TOP LEVEL ARGUMENTS")]
7pub struct TLAOpts {7pub struct TLAOpts {
8 /// Add top level string argument.8 /// Add top level string argument.
9 /// Top level arguments will be passed to function before manifestification stage.9 /// Top level arguments will be passed to function before manifestification stage.
modifiedcrates/jrsonnet-cli/src/trace.rsdiffbeforeafterboth
1use crate::ConfigureState;1use crate::ConfigureState;
2use clap::Clap;2use clap::Parser;
3use jrsonnet_evaluator::{3use jrsonnet_evaluator::{
4 error::Result,4 error::Result,
5 trace::{CompactFormat, ExplainingFormat, PathResolver},5 trace::{CompactFormat, ExplainingFormat, PathResolver},
24 }24 }
25}25}
2626
27#[derive(Clap)]27#[derive(Parser)]
28#[clap(help_heading = "STACK TRACE VISUAL")]28#[clap(next_help_heading = "STACK TRACE VISUAL")]
29pub struct TraceOpts {29pub struct TraceOpts {
30 /// Format of stack traces' display in console.30 /// Format of stack traces' display in console.
31 /// `compact` format only shows `filename:line:column`s31 /// `compact` format only shows `filename:line:column`s