Skip to content
/ quicli Public
forked from killercup/quicli

Quickly build cool CLI apps in Rust.

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

vitiral/quicli

 
 

Repository files navigation

QuiCLI

Quickly build cool CLI apps in Rust.

Build Status Documentation License crates.io

Get started

  1. Create a new Rust binary project called "head" with cargo new --bin head.

  2. Add quicli as an dependency in your Cargo.toml:

    [dependencies]
    quicli = "0.1"

    And, to be able to use all the features, also add these two goodies:

    structopt = "0.1"
    serde = "1"
  3. Now, open up your src/main.rs. Let's import all the good stuff:

    #[macro_use] extern crate quicli;
    use quicli::prelude::*;

    That's it. That's all the imports you should need for now.

  4. Now, quickly write a cool CLI (it's also okay to type slowly):

    // Add cool slogan for your app here, e.g.:
    /// Get first n lines of a file
    #[derive(Debug, StructOpt)]
    struct Cli {
        // Add a CLI argument `--count`/-n` that defaults to 3, and has this help text:
        /// How many lines to get
        #[structopt(long = "count", short = "n", default_value = "3")]
        count: usize,
        // Add a positional argument that the user has to supply:
        /// The file to read
        file: String,
        /// Pass many times for more log output
        #[structopt(long = "verbosity", short = "v")]
        verbosity: u64,
    }
    
    main!(|args: Cli, log_level: verbosity| {
        let data = read_file(&args.file)?;
        info!("Reading first {} lines of {:?}", args.count, args.file);
        data.lines().take(args.count).for_each(|line| println!("{}", line));
    });

    (You can find out about the possible attributes on the Cli struct in structopt's documentation. You can find out more about the main macro in quicli's API documentaton.)

  5. Give it a spin!

    1. cargo run it! Did you see a nice error?
    2. What does cargo run -- Cargo.toml show you?
    3. How about cargo run -- Cargo.toml --count=4 or cargo run -- Cargo.toml -n 2?
    4. cargo run -- --help -- how cool is that?
    5. More fun: Try --cont 4 (with the missing u).
    6. You like log messages? That's what we added the verbosity field for! Give cargo run -- Cargo.toml -vv a try!

Thanks

This is only possible because of all the awesome libraries included here:

  • Structopt and Clap for the nice CLI with awesome argument handling, great error messages, and nice composability!
  • Serde for handling all things serializing and deserializing
  • failure for ergonomic error handling.
  • …and more to come!

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

Quickly build cool CLI apps in Rust.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 100.0%