Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Only Help arg works #203

Open
LeakyBucket opened this issue Oct 24, 2016 · 2 comments
Open

Only Help arg works #203

LeakyBucket opened this issue Oct 24, 2016 · 2 comments

Comments

@LeakyBucket
Copy link

I have the following USAGE trimmed way down to try and find the thing I was misunderstanding:

const USAGE: &'static str = "
App Therapy.

Usage:
  app_therapy (-h | --help)
  app_therapy --agent

Options:
  -h, --help                Show this screen
  --agent                   Launch in agent mode (Listen for incomming commands)
";

#[derive(Debug, RustcDecodable)]
struct Args {
    flag_agent: bool
}

However when I try to run the binary with the --agent flag I get the following error:

thread 'main' panicked at 'I don't know how to read into a nil value.', /Users/leakybucket/.cargo/registry/src/github.com-1ecc6299db9ec823/docopt-0.6.86/src/dopt.rs:735

Here is the full backtrace:

thread 'main' panicked at 'I don't know how to read into a nil value.', /Users/leakybucket/.cargo/registry/src/github.com-1ecc6299db9ec823/docopt-0.6.86/src/dopt.rs:735
stack backtrace:
   1:        0x10e147b88 - std::sys::backtrace::tracing::imp::write::h22f199c1dbb72ba2
   2:        0x10e149f0f - std::panicking::default_hook::{{closure}}::h9a389c462b6a22dd
   3:        0x10e148fef - std::panicking::default_hook::h852b4223c1c00c59
   4:        0x10e1495b6 - std::panicking::rust_panic_with_hook::hcd9d05f53fa0dafc
   5:        0x10df9bec3 - std::panicking::begin_panic::hc03e2830c2c89a5f
   6:        0x10dfebe81 - <docopt::dopt::Decoder as rustc_serialize::serialize::Decoder>::read_nil::h830a130f314b5572
   7:        0x10df3642b - <() as rustc_serialize::serialize::Decodable>::decode::hc9e1e68be3f7a628
   8:        0x10df374f4 - docopt::dopt::ArgvMap::decode::h50ebc5ce7e0a44e8
   9:        0x10df387d5 - docopt::dopt::Docopt::decode::{{closure}}::hf7f142d96a0c9cb5
  10:        0x10df3408d - <core::result::Result<T, E>>::and_then::h4cffc7acd8092700
  11:        0x10df373a4 - docopt::dopt::Docopt::decode::h41e07a6ddfdd9b9b
  12:        0x10df3888f - app_therapy::main::{{closure}}::h24e4c3559ed7fef9
  13:        0x10df34437 - <core::result::Result<T, E>>::and_then::h6197694caaa25e65
  14:        0x10df38172 - app_therapy::main::h588fb001d8ecd459
  15:        0x10e14a4ca - __rust_maybe_catch_panic
  16:        0x10e148ad6 - std::rt::lang_start::h14cbded5fe3cd915
  17:        0x10df38929 - main

I'm running the following toolchain

nightly-x86_64-apple-darwin (default)
rustc 1.14.0-nightly (f09420685 2016-10-20)
@BurntSushi
Copy link
Member

Could you please include the full source code you're using that produce the error? It seems you've only included part of it. Without the other part, I can't actually reproduce your problem.

See also: #89

@LeakyBucket
Copy link
Author

Sorry about that.

extern crate app_therapy;
extern crate rustc_serialize;
extern crate docopt;

use docopt::Docopt;
use app_therapy::config;

const USAGE: &'static str = "
App Therapy.

Usage:
  app_therapy (-h | --help)
  app_therapy --agent

Options:
  -h, --help                Show this screen
  --agent                   Launch in agent mode (Listen for incomming commands)
";

#[derive(Debug, RustcDecodable)]
struct Args {
    flag_agent: bool
}

fn main() {
    let args = Docopt::new(USAGE)
                      .and_then(|d| d.decode())
                      .unwrap_or_else(|e| e.exit());

    let config = match config::load_config() {
        Some(config) => config,
        None => panic!("Failed to parse config file!"),
    };

    println!("User: {}\nPassword: {}", config.user.login, config.user.password);
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants