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

Defaults fail to load #182

Open
Jengamon opened this issue Apr 25, 2016 · 7 comments
Open

Defaults fail to load #182

Jengamon opened this issue Apr 25, 2016 · 7 comments

Comments

@Jengamon
Copy link

I have this usage string here, nearly verbatim:

Validates and packages a ***** project folder.

Usage:
    *******-packer <folder> [--output=FILE]
    *******-packer (--help | --version)
Options:
    --help          # Display this help message.
    --version       # Displays the program version.
    --output=<file> # Specifies a output name [default: game.grav].

Whenever I run it using this struct:

#[derive(RustcDecodable)]
struct Args {
    arg_folder: Option<String>,
    flag_output: String,
    flag_help: bool,
    flag_version: bool
}

and I use the command line: *******-packer game, it gives me "" for flag_output, even though I specified a default. Is there anything I'm doing wrong?

@BurntSushi
Copy link
Member

Could you please provide source code that I can compile and run? I can't reproduce your problem.

My src/main.rs:

extern crate docopt;
extern crate rustc_serialize;

use docopt::Docopt;

const USAGE: &'static str = "
Usage:
    prog <folder> [--output=FILE]
    prog (--help | --version)
Options:
    --help           # Display this help message.
    --version        # Displays the program version.
    --output=<file>  # Specifies a output name [default: game.grav].
";

#[derive(Debug, RustcDecodable)]
struct Args {
    arg_folder: Option<String>,
    flag_output: String,
    flag_help: bool,
    flag_version: bool,
}

fn main() {
    let args: Args = Docopt::new(USAGE).and_then(|d| d.decode())
                                       .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
}

My Cargo.toml:

[package]
name = "docopt-182"
version = "0.1.0"
authors = ["Andrew Gallant <[email protected]>"]

[dependencies]
docopt = "0.6"
rustc-serialize = "0.3"

And running it:

$ cargo build
$ ./target/debug/docopt-182 game
Args { arg_folder: Some("game"), flag_output: "game.grav", flag_help: false, flag_version: false }

Which shows that flag_output gets the correct default value of "game.grav".

@Jengamon
Copy link
Author

Jengamon commented Apr 25, 2016

My main.rs:

extern crate tar;
extern crate bzip2;
extern crate base64;
extern crate docopt;
extern crate rustc_serialize;

const USAGE: &'static str = "
Validates and packages a Gravity project folder.

Usage:
    gravity-packer <folder> [--output=FILE]
    gravity-packer (--help | --version)
Options:
    --help          # Display this help message.
    --version       # Displays the program version.
    --output=FILE   # Specifies a output name [default: game.grav].
";

#[derive(Debug, RustcDecodable)]
struct Args {
    arg_folder: Option<String>,
    flag_output: String,
    flag_help: bool,
    flag_version: bool
}

use docopt::Docopt;

fn main() {
    let args: Args = Docopt::new(USAGE)
                            .and_then(|d| d.decode())
                            .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
    if args.arg_folder.is_some() {
        // Read folder w/ output
        println!("Output to {}?", args.flag_output);
    } else if args.flag_help {
        println!("{}", USAGE)
    } else if args.flag_version {
        println!("Version {}", option_env!("CARGO_PKG_VERSION").unwrap_or("unknown"))
    }
}

My Cargo.toml:

[package]
name = "gravity-packer"
version = "0.1.0"
authors = ["Bobhostern <[email protected]>"]

[dependencies]
base64 = "0.1"
bzip2 = "0.3"
tar = "0.4"
docopt = "0.6"
rustc-serialize = "0.3"
walkdir = "0.1"

When I run the program with cargo run -- game, I get:

Compiling gravity-packer v0.1.0 (file:///C:/Users/Bobho_000/Documents/Rust/gravity/packer)
     Running `target\debug\gravity-packer.exe game`
Args { arg_folder: Some("game"), flag_output: "", flag_help: false, flag_version: false }
Output to ?

Using windows cmd.exe, and even your example produces no flag_output. 😖 I dunno what's going on.

@BurntSushi
Copy link
Member

@Bobhostern Can you show your Cargo.lock file?

@Jengamon
Copy link
Author

Cargo.lock:

[root]
name = "gravity-packer"
version = "0.1.0"
dependencies = [
 "base64 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "bzip2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 "docopt 0.6.80 (registry+https://github.com/rust-lang/crates.io-index)",
 "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "tar 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "walkdir 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "aho-corasick"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "base64"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "bzip2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "bzip2-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "bzip2-sys"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "gcc 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "docopt"
version = "0.6.80"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "regex 0.1.68 (registry+https://github.com/rust-lang/crates.io-index)",
 "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)",
 "strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "filetime"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "gcc"
version = "0.3.27"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "kernel32-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "libc"
version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "memchr"
version = "0.1.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "regex"
version = "0.1.68"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "memchr 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
 "regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
 "thread_local 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
 "utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "regex-syntax"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "rustc-serialize"
version = "0.3.19"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "strsim"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "tar"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "filetime 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "thread-id"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "libc 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "thread_local"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "utf8-ranges"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "walkdir"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
 "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "winapi"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "winapi-build"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"

@BurntSushi
Copy link
Member

I'm unfortunately not sure. If you're still getting the problem even with my code, then maybe there is a Windows bug lurking somewhere? I'll investigate eventually, but it might be a bit. Sorry. :-(

@nixpulvis
Copy link
Contributor

FWIW, I can also seem to replicate this with the following (taken from @BurntSushi's example):

extern crate docopt;

use docopt::Docopt;

const USAGE: &'static str = "
Usage:
    prog <folder> [--output=FILE]
    prog (--help | --version)
Options:
    --help           # Display this help message.
    --version        # Displays the program version.
    --output=<file>  # Specifies a output name [default: game.grav].
";

fn main() {
    let args = Docopt::new(USAGE).and_then(|d| d.parse())
                           .unwrap_or_else(|e| e.exit());
    println!("{:?}", args);
}

@theronic
Copy link

Can corroborate that defaults are not loading for an ARMv6 Raspbian build.

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

4 participants