-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from jordilin/ampscmds
Provide amps list/exec command
- Loading branch information
Showing
11 changed files
with
188 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "git-ar" | ||
version = "0.1.70" | ||
version = "0.1.71" | ||
edition = "2021" | ||
|
||
license = "MIT" | ||
|
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# gr amps | ||
|
||
`gr amps` lists and execute amps. Amps are wrappers around the `gr` command | ||
itself. Amps normally execute gr subcommands and perform additional logic to get | ||
to the desired result. They can also be seen as just `gr` scripts that can be | ||
executed from `gr` itself. A curated list of amps is provided at | ||
<https://github.com/jordilin/gitar-amps>. | ||
|
||
## List available amps | ||
|
||
```bash | ||
gr amps | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
gr amps list | ||
``` | ||
|
||
## Execute an amp in-line | ||
|
||
To execute an amp in-line, you can use the following command: | ||
|
||
```bash | ||
gr amps exec "<amp-name> <arg_0> <arg_1> ... <arg_n>" | ||
``` | ||
|
||
For example: | ||
|
||
```bash | ||
gr amps exec "list-last-assets github.com/jordilin/gitar" | ||
``` | ||
|
||
will print out the URLs of the last stable release assets for the | ||
`github.com/jordilin/gitar` repository. | ||
|
||
**> Note:** Arguments for the amps are optional and the amp name and its | ||
arguments should be enclosed in double quotes. | ||
|
||
## Execute an amp by prompt | ||
|
||
```bash | ||
gr amps exec | ||
``` | ||
|
||
This command will prompt you to select an amp from the list of available amps. | ||
After selecting the amp name, it will prompt you to enter the arguments for the | ||
amp. Upon pressing enter, the amp will be executed. | ||
|
||
The prompt undertands the following prompt queries once an amp has been | ||
selected: | ||
|
||
- `h` or `help` - Show help message for the selected amp. | ||
- `q` or `quit` - Quit the prompt and return back to the CLI. |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
use clap::Parser; | ||
|
||
#[derive(Parser)] | ||
pub struct AmpsCommand { | ||
#[clap(subcommand)] | ||
subcommand: Option<AmpsSubcommand>, | ||
} | ||
|
||
#[derive(Parser)] | ||
enum AmpsSubcommand { | ||
#[clap(about = "List available amps")] | ||
List, | ||
#[clap( | ||
name = "exec", | ||
about = "Execute an amp, either by name or through prompt", | ||
alias = "ex" | ||
)] | ||
Exec(ExecCommand), | ||
} | ||
|
||
#[derive(Parser)] | ||
struct ExecCommand { | ||
/// The name of the amp to execute | ||
#[clap()] | ||
pub name: Option<String>, | ||
} | ||
|
||
pub enum AmpsOptions { | ||
List, | ||
Exec(String), | ||
} | ||
|
||
impl From<AmpsCommand> for AmpsOptions { | ||
fn from(options: AmpsCommand) -> Self { | ||
match options.subcommand { | ||
Some(AmpsSubcommand::List) => AmpsOptions::List, | ||
Some(AmpsSubcommand::Exec(options)) => options.into(), | ||
// defaults to list available amps | ||
None => AmpsOptions::List, | ||
} | ||
} | ||
} | ||
|
||
impl From<ExecCommand> for AmpsOptions { | ||
fn from(options: ExecCommand) -> Self { | ||
match options.name { | ||
Some(name) => AmpsOptions::Exec(name), | ||
// defaults to execute amp through prompt | ||
None => AmpsOptions::Exec(String::new()), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use crate::cli::{Args, Command}; | ||
|
||
use super::*; | ||
|
||
#[test] | ||
fn test_amps_list_command() { | ||
let args = Args::parse_from(vec!["gr", "amps", "list"]); | ||
match args.command { | ||
Command::Amps(AmpsCommand { | ||
subcommand: Some(AmpsSubcommand::List), | ||
}) => {} | ||
_ => panic!("Expected Amp ListCommand"), | ||
} | ||
} | ||
|
||
#[test] | ||
fn test_amps_exec_command() { | ||
let args = Args::parse_from(vec!["gr", "amps", "exec", "amp-name"]); | ||
match args.command { | ||
Command::Amps(AmpsCommand { | ||
subcommand: Some(AmpsSubcommand::Exec(ExecCommand { name })), | ||
}) => { | ||
assert_eq!(name, Some("amp-name".to_string())); | ||
} | ||
_ => panic!("Expected Amp ExecCommand"), | ||
} | ||
} | ||
} |
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
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