Skip to content

Commit eb7388c

Browse files
committed
use structopt instead of clap
many dependencies, but also convenience and safety
1 parent 417c34b commit eb7388c

File tree

4 files changed

+148
-20
lines changed

4 files changed

+148
-20
lines changed

Diff for: Cargo.lock

+118-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ test = false
1313
doctest = false
1414

1515
[dependencies]
16-
clap = "2.31.2"
1716
git-core = { version = "0.1.0", path = "git-core" }
1817
anyhow = "1.0.31"
18+
structopt = "0.3.14"
1919

2020
[profile.release]
2121
panic = 'unwind'

Diff for: src/main.rs

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
#[macro_use]
2-
extern crate clap;
3-
extern crate git_core as git;
41
use anyhow::{Context, Result};
2+
use git_core;
3+
use structopt::StructOpt;
54

6-
mod app {
7-
use clap::{App, AppSettings, SubCommand};
5+
mod options {
6+
use structopt::StructOpt;
87

9-
pub fn new<'a, 'b>() -> App<'a, 'b> {
10-
let app: App = app_from_crate!();
11-
app.setting(AppSettings::SubcommandRequired).subcommand(
12-
SubCommand::with_name("init")
13-
.alias("initialize")
14-
.about("Initialize the repository in the current directory."),
15-
)
8+
#[derive(Debug, StructOpt)]
9+
#[structopt(about = "The git, simply swift")]
10+
#[structopt(setting = structopt::clap::AppSettings::SubcommandRequired)]
11+
pub struct Args {
12+
#[structopt(subcommand)]
13+
pub cmd: Subcommands,
14+
}
15+
16+
#[derive(Debug, StructOpt)]
17+
pub enum Subcommands {
18+
/// Initialize the repository in the current directory.
19+
#[structopt(alias = "initialize")]
20+
Init,
1621
}
1722
}
1823

1924
fn main() -> Result<()> {
20-
let app = app::new();
21-
let matches = app.get_matches();
22-
match matches.subcommand() {
23-
("init", Some(_args)) => {
24-
git::init::repository().with_context(|| "Repository initialization failed")
25+
let args = options::Args::from_args();
26+
match args.cmd {
27+
options::Subcommands::Init => {
28+
git_core::init::repository().with_context(|| "Repository initialization failed")
2529
}
26-
_ => unreachable!(),
2730
}?;
2831
Ok(())
2932
}

Diff for: tasks.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### TODO
2+
3+
* [x] remove failure and replace with quick-check/anyhow
4+
* [x] minimize dependencies and test-runs
5+
* [ ] structopt for grit
6+
* [ ] make parser tests unit tests that are close to the code they test
7+
* [ ] parser tests handle binary strings nicely
8+
* [ ] switch parsing to nom (binary only)

0 commit comments

Comments
 (0)