Skip to content
This repository has been archived by the owner on Aug 23, 2022. It is now read-only.

Rewrite proposal #27

Open
gugahoa opened this issue Jul 31, 2018 · 3 comments
Open

Rewrite proposal #27

gugahoa opened this issue Jul 31, 2018 · 3 comments
Labels
enhancement New feature or request question Further information is requested

Comments

@gugahoa
Copy link
Contributor

gugahoa commented Jul 31, 2018

Hello!
After talking about thunder with @spacekookie, she told me about a effort to rewrite thunder to have a better usability and code.

Thinking about that, I thought about proposing a new way to write thunder apps.
So far my proposal would make a simple hello world look like this:

#![feature(use_extern_macros)]

extern crate thunder_derive;
extern crate thunder;

#[derive(ThunderApp)]
struct Thor {
    /// Bla bla bl
    #[thunder(take_value = false)] // Default is to take value
    drunk: bool,

    /// What will be Thor's age today
    #[thunder(default_value = 1342)] // Can configure flag default value
    age: i32
}

#[thunderclap]
impl Thor {
    /// This is a subcommand, as before
    fn hello(&self, name: Option<&str>) {
        println!("Hello, {}! Nice to meet you, I'm Thor and I'm {} years old", name.unwrap_or("world"), self.age);
    }

    fn me(&self) {
        let drunk = if self.drunk {
            "drunk!"
        } else {
            "not drunk!"
        };

        println!("Huh, me? I'm Thor! And I'm {}");
    }
}

fn main() {
    Thor::start();
}

This is strongly inspired by structopt.
The main idea is to have global args parsing work like normal args do in structopt, and subcommands work as they work right now. Thus being more flexible, while still being fast to iterate.

I couldn't think about how to make subcommand arguments as flexible, but it's on my list of things to improve too

@spacekookie
Copy link
Collaborator

spacekookie commented Jul 31, 2018

Actually, looking at that, the question is if we don't just want to integrate the custom derive part with clapitself (structopt is part of clap as of verion 3.0.0).

At that point the thunder part of the crate would remain the attribute on the impl block.

#[derive(cli)]
struct MyApp {
  // ... do things the same as clap.rs 3.0.0
}

#[thunderclap]
impl MyApp {
  // ... only generate matching code via thunderclap
}

Does this duplicate some workflow? I wouldn't think so, right? Because even with structopt/clapv3 you still need to write all the matching code yourself?

@gugahoa
Copy link
Contributor Author

gugahoa commented Jul 31, 2018

I didn't know about the clap 3.0 and structopt merge! I'll go there and see how it works.

I also think it wouldn't duplicate work as well. I got a new idea on how to make subcommand args more flexible and will also take a look if it can be achieved with clap 3.0 before updating here

@spacekookie spacekookie added enhancement New feature or request question Further information is requested labels Jul 31, 2018
@jjpe
Copy link

jjpe commented Nov 9, 2018

I was about to create a new issue about using this on stable now that proc_macros are stable when I ran across this.
So now I'm thinking that whether it should be its own issue depends on the time frame for this issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants