Last active
May 27, 2018 04:43
-
-
Save gugahoa/25b79588ab566360ef586e57cbef993d to your computer and use it in GitHub Desktop.
Example breaking global option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(proc_macro)] | |
extern crate thunder; | |
extern crate clap; | |
use thunder::thunderclap; | |
struct Loki; | |
#[thunderclap(example: String: "Error, here")] | |
impl Loki { | |
fn hello() { | |
println!("Hello, world!"); | |
} | |
} | |
fn main() { | |
Loki::start(); | |
} | |
/* | |
Compiling cli_example v0.1.0 (file:///home/gustavo.aguiar/git/gugahoa/cli_example) | |
error: custom attribute panicked | |
--> src/main.rs:9:1 | |
| | |
9 | #[thunderclap(example: String: "Error, here")] | |
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| | |
= help: message: index out of bounds: the len is 1 but the index is 1 | |
error: aborting due to previous error | |
error: Could not compile `cli_example`. | |
To learn more, run the command again with --verbose. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(proc_macro)] | |
extern crate thunder; | |
extern crate clap; | |
use thunder::thunderclap; | |
struct Loki; | |
#[thunderclap(example: Option<String>: "Error here")] | |
impl Loki { | |
fn hello() { | |
println!("Hello, {:?}!", Self::example()); | |
} | |
} | |
fn main() { | |
Loki::start(); | |
} | |
/* | |
$ ./target/debug/cli_example hello | |
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', libcore/option.rs:335:21 | |
note: Run with `RUST_BACKTRACE=1` for a backtrace. | |
*/ | |
/* | |
#![feature(prelude_import)] | |
#![no_std] | |
#![feature(proc_macro)] | |
#[prelude_import] | |
use std::prelude::v1::*; | |
#[macro_use] | |
extern crate std; | |
extern crate thunder; | |
extern crate clap; | |
use thunder::thunderclap; | |
struct Loki; | |
impl Loki { | |
fn hello() { Self::example(); } | |
} | |
#[doc = r" This block was generated by thunder v0.0.0"] | |
#[allow(unused)] | |
impl Loki { | |
#[doc = | |
r" Starts the CLI parsing and calls whichever function handles the input"] | |
fn start() { | |
use clap::{App, SubCommand, Arg, AppSettings}; | |
let app = | |
App::new("Loki").about("").setting(AppSettings::SubcommandRequired).arg(Arg::with_name("example").long("--example").short("-e").takes_value(true).help("Error here")).subcommand(SubCommand::with_name("hello").about("")); | |
let args = app.get_matches(); | |
let mut global_match_states = | |
__ThunderDataStaticStore::new_empty_store(); | |
global_match_states.example = | |
match args.value_of("example") { | |
Some(v) => | |
Some(Some(v.parse::<String>().expect("Failed to parse value. Double check!"))), | |
None => None, | |
}; | |
unsafe { __THUNDER_DATA_STATIC = Some(global_match_states); } | |
match args.subcommand() { | |
("hello", Some(m)) => Loki::hello(), | |
_ => { } | |
} | |
} | |
#[allow(unused)] | |
fn example() -> Option<String> { | |
unsafe { | |
__THUNDER_DATA_STATIC.as_ref().unwrap().example.as_ref().unwrap().clone() | |
} | |
} | |
} | |
static mut __THUNDER_DATA_STATIC: Option<__ThunderDataStaticStore> = None; | |
#[doc = r" This block was generated by thunder v0.0.0"] | |
#[allow(unused)] | |
#[doc(hidden)] | |
struct __ThunderDataStaticStore { | |
example: Option<Option<String>>, | |
} | |
#[allow(unused)] | |
#[doc(hidden)] | |
impl __ThunderDataStaticStore { | |
pub fn new_empty_store() -> __ThunderDataStaticStore { | |
__ThunderDataStaticStore{example: None,} | |
} | |
} | |
fn main() { Loki::start(); } | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment