Skip to content

Commit

Permalink
use structopt instead of clap
Browse files Browse the repository at this point in the history
many dependencies, but also convenience and safety
  • Loading branch information
Byron committed Jun 15, 2020
1 parent 417c34b commit eb7388c
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 20 deletions.
119 changes: 118 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ test = false
doctest = false

[dependencies]
clap = "2.31.2"
git-core = { version = "0.1.0", path = "git-core" }
anyhow = "1.0.31"
structopt = "0.3.14"

[profile.release]
panic = 'unwind'
Expand Down
39 changes: 21 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
#[macro_use]
extern crate clap;
extern crate git_core as git;
use anyhow::{Context, Result};
use git_core;
use structopt::StructOpt;

mod app {
use clap::{App, AppSettings, SubCommand};
mod options {
use structopt::StructOpt;

pub fn new<'a, 'b>() -> App<'a, 'b> {
let app: App = app_from_crate!();
app.setting(AppSettings::SubcommandRequired).subcommand(
SubCommand::with_name("init")
.alias("initialize")
.about("Initialize the repository in the current directory."),
)
#[derive(Debug, StructOpt)]
#[structopt(about = "The git, simply swift")]
#[structopt(setting = structopt::clap::AppSettings::SubcommandRequired)]
pub struct Args {
#[structopt(subcommand)]
pub cmd: Subcommands,
}

#[derive(Debug, StructOpt)]
pub enum Subcommands {
/// Initialize the repository in the current directory.
#[structopt(alias = "initialize")]
Init,
}
}

fn main() -> Result<()> {
let app = app::new();
let matches = app.get_matches();
match matches.subcommand() {
("init", Some(_args)) => {
git::init::repository().with_context(|| "Repository initialization failed")
let args = options::Args::from_args();
match args.cmd {
options::Subcommands::Init => {
git_core::init::repository().with_context(|| "Repository initialization failed")
}
_ => unreachable!(),
}?;
Ok(())
}
8 changes: 8 additions & 0 deletions tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### TODO

* [x] remove failure and replace with quick-check/anyhow
* [x] minimize dependencies and test-runs
* [ ] structopt for grit
* [ ] make parser tests unit tests that are close to the code they test
* [ ] parser tests handle binary strings nicely
* [ ] switch parsing to nom (binary only)

0 comments on commit eb7388c

Please sign in to comment.