Compare commits
2 commits
4a57561d7b
...
327d03b066
| Author | SHA1 | Date | |
|---|---|---|---|
|
327d03b066 |
|||
|
44be9e1c1f |
3 changed files with 31 additions and 62 deletions
6
Cargo.lock
generated
6
Cargo.lock
generated
|
|
@ -101,7 +101,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eh"
|
name = "eh"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"dialoguer",
|
"dialoguer",
|
||||||
|
|
@ -116,7 +116,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "eh-log"
|
name = "eh-log"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"yansi",
|
"yansi",
|
||||||
]
|
]
|
||||||
|
|
@ -421,7 +421,7 @@ checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xtask"
|
name = "xtask"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"clap_complete",
|
"clap_complete",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ edition = "2024"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
readme = true
|
readme = true
|
||||||
rust-version = "1.91.0"
|
rust-version = "1.91.0"
|
||||||
version = "0.1.5"
|
version = "0.1.6"
|
||||||
|
|
||||||
[workspace.dependencies]
|
[workspace.dependencies]
|
||||||
clap = { default-features = false, features = [ "std", "help", "derive" ], version = "4.5.56" }
|
clap = { default-features = false, features = [ "std", "help", "derive" ], version = "4.5.56" }
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
use std::{env, path::Path};
|
use std::{env, path::Path};
|
||||||
|
|
||||||
use eh::{Cli, Command, CommandFactory, Parser};
|
use eh::{Cli, Command, CommandFactory, Parser};
|
||||||
use error::Result;
|
|
||||||
use yansi::Paint;
|
use yansi::Paint;
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
|
|
@ -26,11 +25,30 @@ fn main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Design partially taken from Stash
|
fn handle_command(command: &str, args: &[String]) -> error::Result<i32> {
|
||||||
|
let hash_extractor = util::RegexHashExtractor;
|
||||||
|
let fixer = util::DefaultNixFileFixer;
|
||||||
|
let classifier = util::DefaultNixErrorClassifier;
|
||||||
|
|
||||||
|
match command {
|
||||||
|
"update" => commands::update::handle_update(args),
|
||||||
|
"run" | "shell" | "build" => {
|
||||||
|
commands::handle_nix_command(
|
||||||
|
command,
|
||||||
|
args,
|
||||||
|
&hash_extractor,
|
||||||
|
&fixer,
|
||||||
|
&classifier,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn dispatch_multicall(
|
fn dispatch_multicall(
|
||||||
app_name: &str,
|
app_name: &str,
|
||||||
args: std::env::Args,
|
args: std::env::Args,
|
||||||
) -> Option<Result<i32>> {
|
) -> Option<error::Result<i32>> {
|
||||||
let rest: Vec<String> = args.collect();
|
let rest: Vec<String> = args.collect();
|
||||||
|
|
||||||
let subcommand = match app_name {
|
let subcommand = match app_name {
|
||||||
|
|
@ -61,31 +79,10 @@ fn dispatch_multicall(
|
||||||
return Some(Ok(0));
|
return Some(Ok(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
if subcommand == "update" {
|
Some(handle_command(subcommand, &rest))
|
||||||
return Some(commands::update::handle_update(&rest));
|
|
||||||
}
|
|
||||||
|
|
||||||
let hash_extractor = util::RegexHashExtractor;
|
|
||||||
let fixer = util::DefaultNixFileFixer;
|
|
||||||
let classifier = util::DefaultNixErrorClassifier;
|
|
||||||
|
|
||||||
Some(match subcommand {
|
|
||||||
"run" | "shell" | "build" => {
|
|
||||||
commands::handle_nix_command(
|
|
||||||
subcommand,
|
|
||||||
&rest,
|
|
||||||
&hash_extractor,
|
|
||||||
&fixer,
|
|
||||||
&classifier,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
// subcommand is assigned from the match on app_name above;
|
|
||||||
// only "run"/"shell"/"build" are possible values.
|
|
||||||
_ => unreachable!(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_app() -> Result<i32> {
|
fn run_app() -> error::Result<i32> {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
let bin = args.next().unwrap_or_else(|| "eh".to_string());
|
let bin = args.next().unwrap_or_else(|| "eh".to_string());
|
||||||
let app_name = Path::new(&bin)
|
let app_name = Path::new(&bin)
|
||||||
|
|
@ -100,42 +97,14 @@ fn run_app() -> Result<i32> {
|
||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let hash_extractor = util::RegexHashExtractor;
|
|
||||||
let fixer = util::DefaultNixFileFixer;
|
|
||||||
let classifier = util::DefaultNixErrorClassifier;
|
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Some(Command::Run { args }) => {
|
Some(Command::Run { args }) => handle_command("run", &args),
|
||||||
commands::handle_nix_command(
|
|
||||||
"run",
|
|
||||||
&args,
|
|
||||||
&hash_extractor,
|
|
||||||
&fixer,
|
|
||||||
&classifier,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
Some(Command::Shell { args }) => {
|
Some(Command::Shell { args }) => handle_command("shell", &args),
|
||||||
commands::handle_nix_command(
|
|
||||||
"shell",
|
|
||||||
&args,
|
|
||||||
&hash_extractor,
|
|
||||||
&fixer,
|
|
||||||
&classifier,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
Some(Command::Build { args }) => {
|
Some(Command::Build { args }) => handle_command("build", &args),
|
||||||
commands::handle_nix_command(
|
|
||||||
"build",
|
|
||||||
&args,
|
|
||||||
&hash_extractor,
|
|
||||||
&fixer,
|
|
||||||
&classifier,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
|
|
||||||
Some(Command::Update { args }) => commands::update::handle_update(&args),
|
Some(Command::Update { args }) => handle_command("update", &args),
|
||||||
|
|
||||||
None => {
|
None => {
|
||||||
Cli::command().print_help()?;
|
Cli::command().print_help()?;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue