Created
August 25, 2020 05:09
-
-
Save d-e-s-o/4653b9ba305654bd6733573913c011a3 to your computer and use it in GitHub Desktop.
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(prelude_import)] | |
#[prelude_import] | |
use std::prelude::v1::*; | |
#[macro_use] | |
extern crate std; | |
use structopt::StructOpt; | |
macro_rules! Command { | |
($ name : ident, [# [$ meta : meta] $ var : ident ($ inner : ty)]) => | |
{ | |
# [derive (Debug, PartialEq, structopt :: StructOpt)] enum $ name | |
{ # [$ meta] $ var ($ inner), } | |
} ; | |
} | |
enum GitCmd { | |
#[ | |
structopt(external_subcommand)] | |
Ext(Vec<String>), | |
} | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl ::core::fmt::Debug for GitCmd { | |
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { | |
match (&*self,) { | |
(&GitCmd::Ext(ref __self_0),) => { | |
let mut debug_trait_builder = f.debug_tuple("Ext"); | |
let _ = debug_trait_builder.field(&&(*__self_0)); | |
debug_trait_builder.finish() | |
} | |
} | |
} | |
} | |
impl ::core::marker::StructuralPartialEq for GitCmd { } | |
#[automatically_derived] | |
#[allow(unused_qualifications)] | |
impl ::core::cmp::PartialEq for GitCmd { | |
#[inline] | |
fn eq(&self, other: &GitCmd) -> bool { | |
match (&*self, &*other) { | |
(&GitCmd::Ext(ref __self_0), &GitCmd::Ext(ref __arg_1_0)) => | |
(*__self_0) == (*__arg_1_0), | |
} | |
} | |
#[inline] | |
fn ne(&self, other: &GitCmd) -> bool { | |
match (&*self, &*other) { | |
(&GitCmd::Ext(ref __self_0), &GitCmd::Ext(ref __arg_1_0)) => | |
(*__self_0) != (*__arg_1_0), | |
} | |
} | |
} | |
#[allow(unknown_lints)] | |
#[allow(unused_variables, dead_code, unreachable_code)] | |
#[allow(clippy :: style, clippy :: complexity, clippy :: pedantic, clippy :: | |
restriction, clippy :: perf, clippy :: deprecated, clippy :: nursery, | |
clippy :: cargo)] | |
#[deny(clippy :: correctness)] | |
impl ::structopt::StructOpt for GitCmd { | |
fn clap<'a, 'b>() -> ::structopt::clap::App<'a, 'b> { | |
let app = | |
::structopt::clap::App::new("foo").setting(::structopt::clap::AppSettings::SubcommandRequiredElseHelp); | |
<Self as ::structopt::StructOptInternal>::augment_clap(app) | |
} | |
fn from_clap(matches: &::structopt::clap::ArgMatches) -> Self { | |
<GitCmd as | |
::structopt::StructOptInternal>::from_subcommand(matches.subcommand()).expect("structopt misuse: You likely tried to #[flatten] a struct \ | |
that contains #[subcommand]. This is forbidden.") | |
} | |
} | |
#[allow(unused_variables)] | |
#[allow(unknown_lints)] | |
#[allow(clippy :: style, clippy :: complexity, clippy :: pedantic, clippy :: | |
restriction, clippy :: perf, clippy :: deprecated, clippy :: nursery, | |
clippy :: cargo)] | |
#[deny(clippy :: correctness)] | |
#[allow(dead_code, unreachable_code)] | |
impl ::structopt::StructOptInternal for GitCmd { | |
fn augment_clap<'a, 'b>(app: ::structopt::clap::App<'a, 'b>) | |
-> ::structopt::clap::App<'a, 'b> { | |
let app = app; | |
let app = | |
app.setting(::structopt::clap::AppSettings::AllowExternalSubcommands); | |
; | |
app.version("0.1.0") | |
} | |
fn from_subcommand<'a, | |
'b>(sub: | |
(&'b str, | |
Option<&'b ::structopt::clap::ArgMatches<'a>>)) | |
-> Option<Self> { | |
match sub { | |
other => { | |
; | |
match other { | |
("", ::std::option::Option::None) => None, | |
(external, Some(matches)) => { | |
::std::option::Option::Some(GitCmd::Ext(::std::iter::once(::std::string::String::from(external)).chain(matches.values_of("").into_iter().flatten().map(::std::string::String::from)).collect::<::std::vec::Vec<_>>())) | |
} | |
(external, None) => { | |
::std::option::Option::Some(GitCmd::Ext(::std::iter::once(::std::string::String::from(external)).collect::<::std::vec::Vec<_>>())) | |
} | |
} | |
} | |
} | |
} | |
fn is_subcommand() -> bool { true } | |
} | |
// Works: | |
//#[derive(Debug, PartialEq, StructOpt)] | |
//enum GitCmd { | |
// #[structopt(external_subcommand)] | |
// Ext(Vec<String>), | |
//} | |
fn main() { | |
{ | |
{ | |
match (&GitCmd::from_iter(&["test", "git", "status"]), | |
&GitCmd::Ext(<[_]>::into_vec(box | |
["git".to_string(), | |
"status".to_string()]))) | |
{ | |
(left_val, right_val) => { | |
if !(*left_val == *right_val) { | |
{ | |
::std::rt::begin_panic_fmt(&::core::fmt::Arguments::new_v1(&["assertion failed: `(left == right)`\n left: `", | |
"`,\n right: `", | |
"`"], | |
&match (&&*left_val, | |
&&*right_val) | |
{ | |
(arg0, | |
arg1) | |
=> | |
[::core::fmt::ArgumentV1::new(arg0, | |
::core::fmt::Debug::fmt), | |
::core::fmt::ArgumentV1::new(arg1, | |
::core::fmt::Debug::fmt)], | |
})) | |
} | |
} | |
} | |
} | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment