Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use and import cli.yml file to finish project-1 failed #375

Open
PhzCode opened this issue Nov 6, 2020 · 0 comments
Open

use and import cli.yml file to finish project-1 failed #375

PhzCode opened this issue Nov 6, 2020 · 0 comments
Labels
type/question Further information is requested

Comments

@PhzCode
Copy link

PhzCode commented Nov 6, 2020

General Question

The sourse in github using clap crate is coding in the kvs.rs file. However, I use the cli.yml to do it, and I can not pass some test cases.

cli.yml file

name: project-1
version: "1.0"
author: *
about: get some args to do something
args:
    - INPUT:
        help: the flag to input
        required: true
        index: 1
    - V:
        short: V
        multiple: false
        help: show the version
subcommands:
    - set:
        about: to set the key-value with the input
        version: "1.0"
        author: *
        args:
            - key:
                index: 1
                help: the key is needed.
                required: true
            - value:
                index: 2
                help: the value is needed.
                required: true
    - get:
        about: to get the value by the key
        version: "1.0"
        author: *
        args:
            - key:
                index: 1
                help: the key is needed.
                required: true
    - rm:
        about: to remove the key-value by the key
        version: "1.0"
        author: *
        args:
            - key:
                index: 1
                help: the key is needed.
                required: true
    

kvs.rs file

#[macro_use]
extern crate clap;
use clap::App;
use std::process::exit;

fn main() {

    let yaml = load_yaml!("cli.yml");
    let matches = App::from_yaml(yaml).get_matches();

    if matches.is_present("V") {
        println!(env!("CARGO_PKG_VERSION"));
    }

    match matches.subcommand() {
        ("set", Some(_matches)) => {
            eprintln!("unimplemented");
            exit(1);
        }
        ("get", Some(_matches)) => {
            eprintln!("unimplemented");
            exit(1);
        }
        ("rm", Some(_matches)) => {
            eprintln!("unimplemented");
            exit(1);
        }
        _ => unreachable!(),
    }
}

the test result

running 13 tests
test cli_no_args ... ok
test cli_invalid_subcommand ... ok
test get_non_existent_value ... ok
test cli_get ... FAILED
test get_stored_value ... ok
test overwrite_value ... ok
test remove_key ... ok
test cli_rm ... FAILED
test cli_set ... FAILED
test cli_invalid_get ... ok
test cli_invalid_rm ... ok
test cli_version ... FAILED
test cli_invalid_set ... ok
@PhzCode PhzCode added the type/question Further information is requested label Nov 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant