Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
kevgo committed Oct 21, 2024
1 parent 385c753 commit 2a0dd03
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 100 deletions.
132 changes: 78 additions & 54 deletions src/cli/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use super::{AppVersion, Command};
use crate::cmd::run;
use crate::prelude::*;

/// all arguments that can be provided via the CLI
Expand Down Expand Up @@ -119,12 +120,14 @@ pub fn parse(mut cli_args: impl Iterator<Item = String>) -> Result<Args> {
} else {
Ok(Args {
command: Command::RunApp {
app,
version,
app_args,
error_on_output,
optional,
verbose,
run_args: run::Args {
app,
version,
app_args,
error_on_output,
optional,
verbose,
},
},
})
}
Expand Down Expand Up @@ -164,6 +167,7 @@ mod tests {
mod rta_arguments {
use super::parse_args;
use crate::cli::{Args, Command};
use crate::cmd::run;
use crate::config::{AppName, Version};
use crate::prelude::*;
use big_s::S;
Expand Down Expand Up @@ -211,6 +215,7 @@ mod tests {
mod error_on_output {
use super::super::parse_args;
use crate::cli::{Args, Command};
use crate::cmd::run;
use crate::config::AppName;
use crate::prelude::*;

Expand All @@ -219,12 +224,14 @@ mod tests {
let have = parse_args(vec!["rta", "--error-on-output", "app"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: None,
app_args: vec![],
error_on_output: true,
optional: false,
verbose: false,
run_args: run::Args {
app: AppName::from("app"),
version: None,
app_args: vec![],
error_on_output: true,
optional: false,
verbose: false,
},
},
});
pretty::assert_eq!(have, want);
Expand Down Expand Up @@ -308,6 +315,7 @@ mod tests {
mod verbose {
use super::super::parse_args;
use crate::cli::{Args, Command};
use crate::cmd::run;
use crate::config::{AppName, Version};
use crate::prelude::*;

Expand All @@ -316,12 +324,14 @@ mod tests {
let have = parse_args(vec!["rta", "--verbose", "app@2"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: true,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: true,
},
},
});
pretty::assert_eq!(have, want);
Expand All @@ -332,12 +342,14 @@ mod tests {
let have = parse_args(vec!["rta", "-v", "app@2"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: true,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: true,
},
},
});
pretty::assert_eq!(have, want);
Expand All @@ -363,12 +375,14 @@ mod tests {
let have = parse_args(vec!["rta", "--optional", "app@2", "arg1"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("arg1")],
error_on_output: false,
optional: true,
verbose: false,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("arg1")],
error_on_output: false,
optional: true,
verbose: false,
},
},
});
pretty::assert_eq!(have, want);
Expand Down Expand Up @@ -478,6 +492,7 @@ mod tests {
mod application_arguments {
use super::parse_args;
use crate::cli::{args, Command};
use crate::cmd::run;
use crate::config::{AppName, Version};
use args::Args;
use big_s::S;
Expand All @@ -487,12 +502,14 @@ mod tests {
let have = parse_args(vec!["rta", "app@2"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: false,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![],
error_on_output: false,
optional: false,
verbose: false,
},
},
});
pretty::assert_eq!(have, want);
Expand All @@ -503,12 +520,14 @@ mod tests {
let have = parse_args(vec!["rta", "app@2", "--arg1", "arg2"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--arg1"), S("arg2")],
error_on_output: false,
optional: false,
verbose: false,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--arg1"), S("arg2")],
error_on_output: false,
optional: false,
verbose: false,
},
},
});
pretty::assert_eq!(have, want);
Expand All @@ -518,6 +537,7 @@ mod tests {
mod rta_and_app_arguments {
use super::parse_args;
use crate::cli::{Args, Command};
use crate::cmd::run;
use crate::config::{AppName, Version};
use big_s::S;

Expand All @@ -526,12 +546,14 @@ mod tests {
let have = parse_args(vec!["rta", "--verbose", "app@2", "--arg1", "arg2"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--arg1"), S("arg2")],
error_on_output: false,
optional: false,
verbose: true,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--arg1"), S("arg2")],
error_on_output: false,
optional: false,
verbose: true,
},
},
});
pretty::assert_eq!(have, want);
Expand All @@ -542,12 +564,14 @@ mod tests {
let have = parse_args(vec!["rta", "app@2", "--verbose", "--version"]);
let want = Ok(Args {
command: Command::RunApp {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--verbose"), S("--version")],
error_on_output: false,
optional: false,
verbose: false,
run_args: run::Args {
app: AppName::from("app"),
version: Some(Version::from("2")),
app_args: vec![S("--verbose"), S("--version")],
error_on_output: false,
optional: false,
verbose: false,
},
},
});
pretty::assert_eq!(have, want);
Expand Down
37 changes: 7 additions & 30 deletions src/cli/command.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,18 @@
use crate::cmd::run;
use crate::config::{AppName, Version};

/// the main commands that run-this-app can execute
#[derive(Debug, PartialEq)]
pub enum Command {
AppsLong,
AppsShort,
Available {
app: AppName,
version: Option<Version>,
verbose: bool,
},
RunApp {
app: AppName,
version: Option<Version>,
app_args: Vec<String>,
error_on_output: bool,
optional: bool,
verbose: bool,
},
Available { app: AppName, version: Option<Version>, verbose: bool },
RunApp { run_args: run::Args },
DisplayHelp,
Setup,
Test {
app: Option<AppName>,
verbose: bool,
},
Which {
app: AppName,
version: Option<Version>,
verbose: bool,
},
Update {
verbose: bool,
},
Test { app: Option<AppName>, verbose: bool },
Which { app: AppName, version: Option<Version>, verbose: bool },
Update { verbose: bool },
Version,
Versions {
app: AppName,
amount: usize,
verbose: bool,
},
Versions { app: AppName, amount: usize, verbose: bool },
}
1 change: 1 addition & 0 deletions src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub fn run(args: Args) -> Result<ExitCode> {
}

/// data needed to run an executable
#[derive(Debug, PartialEq)]
pub struct Args {
/// name of the app to execute
pub app: AppName,
Expand Down
17 changes: 1 addition & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ mod subshell;
mod yard;

use cli::Command;
use cmd::run;
use logger::Log;
use std::process::ExitCode;

Expand All @@ -36,21 +35,7 @@ fn inner() -> prelude::Result<ExitCode> {
Command::AppsLong => Ok(cmd::apps::long()),
Command::AppsShort => Ok(cmd::apps::short()),
Command::Available { app, version, verbose } => cmd::available(&app, version, verbose),
Command::RunApp {
verbose,
app,
version,
app_args,
error_on_output,
optional,
} => cmd::run(run::Args {
app,
version,
app_args,
error_on_output,
optional,
verbose,
}),
Command::RunApp { run_args } => cmd::run(run_args),
Command::DisplayHelp => Ok(cmd::help()),
Command::Setup => cmd::setup(),
Command::Test { app, verbose } => cmd::test(app, verbose),
Expand Down

0 comments on commit 2a0dd03

Please sign in to comment.