1 unstable release

Uses old Rust 2015

0.1.0 Nov 5, 2015

#1912 in #command-line

18KB
362 lines

CLIne - a command line API for rust Build Status

Documentation

The cline crate provides an API that allows users to register CLI commands with an execute and dynamic suggest callback to help implementing command line clients that support auto completion of commands

Usage

extern crate cline;
use cline::{Cli, cline_run};

fn main() {
    let mut cli = Cli::new();

    cli.register(vec!["foo", "bar"], | _ | { println!("running foo bar") });
    cli.register(vec!["foo", "baz"], | _ | { println!("running foo baz") });

    cline_run(&mut cli);
}

Contributors

License

Copyright © 2015 Christoph Sitter

Distributed under the Apache License Version 2.0.


lib.rs:

The cline crate provides an API that allows users to register CLI commands with an execute and dynamic suggest callback to help implementing command line clients that support auto completion of commands

Getting started

The cline API works by creating an instance of the struct Cli and calling register, execute or complete on it

Create a new Cli object:

let mut cli = Cli::new();

Register a function:

cli.register(vec!["list", "files"], | args | { println!("called with: {:?}", args); });

Get suggestions for autocompletion:

cli.complete("l"); //returns vec!["list"]
cli.complete("list"); //returns vec!["files"]

Execute command aka call registered exec closure:

cli.exec("list files"); //calls the registered closure

Dependencies

~120KB