-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add initial version of 'lean-cli' feature toggle, but…
…nested subcommands are not allowed. Maybe this tells me that I want two binaries, one for plumbing, one for everything else.
- Loading branch information
Showing
5 changed files
with
152 additions
and
51 deletions.
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 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 |
---|---|---|
@@ -1,61 +1,124 @@ | ||
#![forbid(unsafe_code)] | ||
|
||
use anyhow::Result; | ||
use gitoxide_core as core; | ||
use std::io::{stderr, stdout}; | ||
use structopt::StructOpt; | ||
|
||
mod options { | ||
use std::path::PathBuf; | ||
use structopt::clap::AppSettings; | ||
#[cfg(feature = "pretty-cli")] | ||
mod pretty { | ||
use anyhow::Result; | ||
use gitoxide_core as core; | ||
use std::io::{stderr, stdout}; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(about = "The git, simply swift")] | ||
#[structopt(settings = &[AppSettings::SubcommandRequired, | ||
mod options { | ||
use std::path::PathBuf; | ||
use structopt::clap::AppSettings; | ||
use structopt::StructOpt; | ||
|
||
#[derive(Debug, StructOpt)] | ||
#[structopt(about = "The git, simply swift")] | ||
#[structopt(settings = &[AppSettings::SubcommandRequired, | ||
AppSettings::ColoredHelp])] | ||
pub struct Args { | ||
#[structopt(subcommand)] | ||
pub cmd: Subcommands, | ||
pub struct Args { | ||
#[structopt(subcommand)] | ||
pub cmd: Subcommands, | ||
} | ||
|
||
/// Low-level commands that are not used every day | ||
#[derive(Debug, StructOpt)] | ||
pub enum Plumbing { | ||
/// Verify the integrity of a pack or index file | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
VerifyPack { | ||
/// The '.pack' or '.idx' file whose checksum to validate. | ||
#[structopt(parse(from_os_str))] | ||
path: PathBuf, | ||
}, | ||
} | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub enum Subcommands { | ||
/// Initialize the repository in the current directory. | ||
#[structopt(alias = "initialize")] | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
Init, | ||
|
||
#[structopt(alias = "p")] | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
Plumbing(Plumbing), | ||
} | ||
} | ||
|
||
/// Low-level commands that are not used every day | ||
#[derive(Debug, StructOpt)] | ||
pub enum Plumbing { | ||
/// Verify the integrity of a pack or index file | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
VerifyPack { | ||
/// The '.pack' file whose checksum to validate. | ||
/// | ||
/// '.pack' files have a 20 byte trailer representing the Sha1 over all the bytes that | ||
/// preceded it. | ||
#[structopt(parse(from_os_str))] | ||
path: PathBuf, | ||
}, | ||
pub fn main() -> Result<()> { | ||
use options::*; | ||
let args = Args::from_args(); | ||
match args.cmd { | ||
Subcommands::Init => core::init(), | ||
Subcommands::Plumbing(cmd) => match cmd { | ||
Plumbing::VerifyPack { path } => { | ||
core::verify_pack_or_pack_index(path, stdout(), stderr()) | ||
} | ||
}, | ||
}?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
#[derive(Debug, StructOpt)] | ||
pub enum Subcommands { | ||
/// Initialize the repository in the current directory. | ||
#[structopt(alias = "initialize")] | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
Init, | ||
#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] | ||
mod lean { | ||
use argh::FromArgs; | ||
|
||
#[structopt(alias = "p")] | ||
#[structopt(setting = AppSettings::ColoredHelp)] | ||
Plumbing(Plumbing), | ||
#[derive(FromArgs)] | ||
/// A simple calculation tool | ||
struct Args { | ||
#[argh(subcommand)] | ||
subcommand: SubCommands, | ||
} | ||
} | ||
|
||
fn main() -> Result<()> { | ||
let args = options::Args::from_args(); | ||
match args.cmd { | ||
options::Subcommands::Init => core::init(), | ||
options::Subcommands::Plumbing(cmd) => match cmd { | ||
options::Plumbing::VerifyPack { path } => { | ||
#[derive(FromArgs, PartialEq, Debug)] | ||
#[argh(subcommand)] | ||
enum SubCommands { | ||
Init(Init), | ||
VerifyPack(VerifyPack), | ||
} | ||
|
||
/// Initialize the repository in the current directory. | ||
#[derive(FromArgs, PartialEq, Debug)] | ||
#[argh(subcommand, name = "init")] | ||
struct Init {} | ||
|
||
/// Initialize the repository in the current directory. | ||
#[derive(FromArgs, PartialEq, Debug)] | ||
#[argh(subcommand, name = "verify-pack")] | ||
struct VerifyPack { | ||
/// the '.pack' or '.idx' file whose checksum to validate. | ||
#[argh(option)] | ||
path: PathBuf, | ||
} | ||
|
||
use anyhow::Result; | ||
use gitoxide_core as core; | ||
use std::{ | ||
io::{stderr, stdout}, | ||
path::PathBuf, | ||
}; | ||
|
||
pub fn main() -> Result<()> { | ||
let cli: Args = argh::from_env(); | ||
match cli.subcommand { | ||
SubCommands::Init(_) => core::init(), | ||
SubCommands::VerifyPack(VerifyPack { path }) => { | ||
core::verify_pack_or_pack_index(path, stdout(), stderr()) | ||
} | ||
}, | ||
}?; | ||
Ok(()) | ||
} | ||
} | ||
} | ||
|
||
use anyhow::Result; | ||
|
||
#[cfg(feature = "pretty-cli")] | ||
fn main() -> Result<()> { | ||
pretty::main() | ||
} | ||
|
||
#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] | ||
fn main() -> Result<()> { | ||
lean::main() | ||
} |