Skip to content

Instantly share code, notes, and snippets.

@matklad
Created February 14, 2017 10:06
Show Gist options
  • Save matklad/672c2fd23235b86949d721d51422be39 to your computer and use it in GitHub Desktop.
Save matklad/672c2fd23235b86949d721d51422be39 to your computer and use it in GitHub Desktop.
trait Command {
fn cli(&self) -> clap::App;
fn execute(&self, config: &Config, args: &clap::Args);
}
trait WsCommand {
fn cli(&self) -> clap::App;
fn execute(&self, config: &Config, ws: &Workspace, args: &clap::Args);
}
impl<T: WsCommand> Command for T {
fn cli(&self) -> clap::App {
<T as WsCommand>::cli(self)
}
fn execute(&self, config: &Config, args: &clap::Args) {
let ws = configure_ws(config, args);
<T as WsCommand>::execute(self, config, ws, args)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment