|
1 | 1 | #![forbid(unsafe_code)]
|
2 | 2 |
|
3 |
| -use anyhow::Result; |
4 |
| -use gitoxide_core as core; |
5 |
| -use std::io::{stderr, stdout}; |
6 |
| -use structopt::StructOpt; |
7 |
| - |
8 |
| -mod options { |
9 |
| - use std::path::PathBuf; |
10 |
| - use structopt::clap::AppSettings; |
| 3 | +#[cfg(feature = "pretty-cli")] |
| 4 | +mod pretty { |
| 5 | + use anyhow::Result; |
| 6 | + use gitoxide_core as core; |
| 7 | + use std::io::{stderr, stdout}; |
11 | 8 | use structopt::StructOpt;
|
12 | 9 |
|
13 |
| - #[derive(Debug, StructOpt)] |
14 |
| - #[structopt(about = "The git, simply swift")] |
15 |
| - #[structopt(settings = &[AppSettings::SubcommandRequired, |
| 10 | + mod options { |
| 11 | + use std::path::PathBuf; |
| 12 | + use structopt::clap::AppSettings; |
| 13 | + use structopt::StructOpt; |
| 14 | + |
| 15 | + #[derive(Debug, StructOpt)] |
| 16 | + #[structopt(about = "The git, simply swift")] |
| 17 | + #[structopt(settings = &[AppSettings::SubcommandRequired, |
16 | 18 | AppSettings::ColoredHelp])]
|
17 |
| - pub struct Args { |
18 |
| - #[structopt(subcommand)] |
19 |
| - pub cmd: Subcommands, |
| 19 | + pub struct Args { |
| 20 | + #[structopt(subcommand)] |
| 21 | + pub cmd: Subcommands, |
| 22 | + } |
| 23 | + |
| 24 | + /// Low-level commands that are not used every day |
| 25 | + #[derive(Debug, StructOpt)] |
| 26 | + pub enum Plumbing { |
| 27 | + /// Verify the integrity of a pack or index file |
| 28 | + #[structopt(setting = AppSettings::ColoredHelp)] |
| 29 | + VerifyPack { |
| 30 | + /// The '.pack' or '.idx' file whose checksum to validate. |
| 31 | + #[structopt(parse(from_os_str))] |
| 32 | + path: PathBuf, |
| 33 | + }, |
| 34 | + } |
| 35 | + |
| 36 | + #[derive(Debug, StructOpt)] |
| 37 | + pub enum Subcommands { |
| 38 | + /// Initialize the repository in the current directory. |
| 39 | + #[structopt(alias = "initialize")] |
| 40 | + #[structopt(setting = AppSettings::ColoredHelp)] |
| 41 | + Init, |
| 42 | + |
| 43 | + #[structopt(alias = "p")] |
| 44 | + #[structopt(setting = AppSettings::ColoredHelp)] |
| 45 | + Plumbing(Plumbing), |
| 46 | + } |
20 | 47 | }
|
21 | 48 |
|
22 |
| - /// Low-level commands that are not used every day |
23 |
| - #[derive(Debug, StructOpt)] |
24 |
| - pub enum Plumbing { |
25 |
| - /// Verify the integrity of a pack or index file |
26 |
| - #[structopt(setting = AppSettings::ColoredHelp)] |
27 |
| - VerifyPack { |
28 |
| - /// The '.pack' file whose checksum to validate. |
29 |
| - /// |
30 |
| - /// '.pack' files have a 20 byte trailer representing the Sha1 over all the bytes that |
31 |
| - /// preceded it. |
32 |
| - #[structopt(parse(from_os_str))] |
33 |
| - path: PathBuf, |
34 |
| - }, |
| 49 | + pub fn main() -> Result<()> { |
| 50 | + use options::*; |
| 51 | + let args = Args::from_args(); |
| 52 | + match args.cmd { |
| 53 | + Subcommands::Init => core::init(), |
| 54 | + Subcommands::Plumbing(cmd) => match cmd { |
| 55 | + Plumbing::VerifyPack { path } => { |
| 56 | + core::verify_pack_or_pack_index(path, stdout(), stderr()) |
| 57 | + } |
| 58 | + }, |
| 59 | + }?; |
| 60 | + Ok(()) |
35 | 61 | }
|
| 62 | +} |
36 | 63 |
|
37 |
| - #[derive(Debug, StructOpt)] |
38 |
| - pub enum Subcommands { |
39 |
| - /// Initialize the repository in the current directory. |
40 |
| - #[structopt(alias = "initialize")] |
41 |
| - #[structopt(setting = AppSettings::ColoredHelp)] |
42 |
| - Init, |
| 64 | +#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] |
| 65 | +mod lean { |
| 66 | + use argh::FromArgs; |
43 | 67 |
|
44 |
| - #[structopt(alias = "p")] |
45 |
| - #[structopt(setting = AppSettings::ColoredHelp)] |
46 |
| - Plumbing(Plumbing), |
| 68 | + #[derive(FromArgs)] |
| 69 | + /// A simple calculation tool |
| 70 | + struct Args { |
| 71 | + #[argh(subcommand)] |
| 72 | + subcommand: SubCommands, |
47 | 73 | }
|
48 |
| -} |
49 | 74 |
|
50 |
| -fn main() -> Result<()> { |
51 |
| - let args = options::Args::from_args(); |
52 |
| - match args.cmd { |
53 |
| - options::Subcommands::Init => core::init(), |
54 |
| - options::Subcommands::Plumbing(cmd) => match cmd { |
55 |
| - options::Plumbing::VerifyPack { path } => { |
| 75 | + #[derive(FromArgs, PartialEq, Debug)] |
| 76 | + #[argh(subcommand)] |
| 77 | + enum SubCommands { |
| 78 | + Init(Init), |
| 79 | + VerifyPack(VerifyPack), |
| 80 | + } |
| 81 | + |
| 82 | + /// Initialize the repository in the current directory. |
| 83 | + #[derive(FromArgs, PartialEq, Debug)] |
| 84 | + #[argh(subcommand, name = "init")] |
| 85 | + struct Init {} |
| 86 | + |
| 87 | + /// Initialize the repository in the current directory. |
| 88 | + #[derive(FromArgs, PartialEq, Debug)] |
| 89 | + #[argh(subcommand, name = "verify-pack")] |
| 90 | + struct VerifyPack { |
| 91 | + /// the '.pack' or '.idx' file whose checksum to validate. |
| 92 | + #[argh(option)] |
| 93 | + path: PathBuf, |
| 94 | + } |
| 95 | + |
| 96 | + use anyhow::Result; |
| 97 | + use gitoxide_core as core; |
| 98 | + use std::{ |
| 99 | + io::{stderr, stdout}, |
| 100 | + path::PathBuf, |
| 101 | + }; |
| 102 | + |
| 103 | + pub fn main() -> Result<()> { |
| 104 | + let cli: Args = argh::from_env(); |
| 105 | + match cli.subcommand { |
| 106 | + SubCommands::Init(_) => core::init(), |
| 107 | + SubCommands::VerifyPack(VerifyPack { path }) => { |
56 | 108 | core::verify_pack_or_pack_index(path, stdout(), stderr())
|
57 | 109 | }
|
58 |
| - }, |
59 |
| - }?; |
60 |
| - Ok(()) |
| 110 | + } |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +use anyhow::Result; |
| 115 | + |
| 116 | +#[cfg(feature = "pretty-cli")] |
| 117 | +fn main() -> Result<()> { |
| 118 | + pretty::main() |
| 119 | +} |
| 120 | + |
| 121 | +#[cfg(all(feature = "lean-cli", not(feature = "pretty-cli")))] |
| 122 | +fn main() -> Result<()> { |
| 123 | + lean::main() |
61 | 124 | }
|
0 commit comments