Skip to content

Commit

Permalink
feat: add alias for component and update fish completion (#149)
Browse files Browse the repository at this point in the history
* feat: add alias for component and update fish completion

* fix: fish completion (#3)
  • Loading branch information
wangl-cc authored Dec 19, 2023
1 parent c030e89 commit e809692
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 49 deletions.
83 changes: 52 additions & 31 deletions maa-cli/share/fish/vendor_completions.d/maa.fish
Original file line number Diff line number Diff line change
@@ -1,47 +1,68 @@
# fish completion file for maa
# Fish completion for maa-cli

# Top level
complete -c maa -n "__fish_use_subcommand" -s h -l help -d 'Print help'
# Global options
complete -c maa -s v -l verbose -d 'Output more information, repeat to increase verbosity'
complete -c maa -s q -l quiet -d 'Output less information, repeat to increase quietness'
complete -c maa -l batch -d 'Enable touch mode'

# help
set -l subcommands install update self hot-update dir version run fight copilot roguelike list complete
complete -c maa -s h -l help -d 'Print help (see more with \'--help\')'
complete -c maa -n "__fish_use_subcommand" -f -a "help" -d 'Print help for given subcommand'
complete -c maa -n "__fish_seen_subcommand_from help" -f -a "$subcommands"

# version
complete -c maa -n "__fish_use_subcommand" -s V -l version -d 'Print version'
complete -c maa -n "__fish_use_subcommand" -f -a "install" -d 'Install maa core and resources'
complete -c maa -n "__fish_use_subcommand" -f -a "update" -d 'Update maa core and resources'
complete -c maa -n "__fish_use_subcommand" -f -a "self" -d 'Manage maa-cli self and maa-run'
complete -c maa -n "__fish_use_subcommand" -f -a "dir" -d 'Print path of maa directories'
complete -c maa -n "__fish_use_subcommand" -f -a "version" -d 'Print version of given component'
complete -c maa -n "__fish_seen_subcommand_from version" -f -a "all cli core"

# Subcommands
complete -c maa -n "__fish_use_subcommand" -f -a "install" -d 'Install maa maa_core and resources'
complete -c maa -n "__fish_use_subcommand" -f -a "update" -d 'Update maa maa_core and resources'
complete -c maa -n "__fish_use_subcommand" -f -a "self" -d 'Manage maa-cli self'
complete -c maa -n "__fish_use_subcommand" -f -a "hot-update" -d 'Hot update for resource'
complete -c maa -n "__fish_use_subcommand" -f -a "dir" -d 'Print path of maa directories'
complete -c maa -n "__fish_use_subcommand" -f -a "run" -d 'Run a predefined task'
complete -c maa -n "__fish_use_subcommand" -f -a "fight" -d 'Run fight task'
complete -c maa -n "__fish_use_subcommand" -f -a "copilot" -d 'Run copilot task'
complete -c maa -n "__fish_use_subcommand" -f -a "roguelike" -d 'Run rouge-like task'
complete -c maa -n "__fish_use_subcommand" -f -a "list" -d 'List all available tasks'
complete -c maa -n "__fish_use_subcommand" -f -a "complete" -d 'Generate completion script for given shell'
complete -c maa -n "__fish_use_subcommand" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'

# Subcommands
## Install and Update
complete -c maa -n "__fish_seen_subcommand_from install update" -f -a "stable beta alpha" -d 'Install maa and resource from given channel'
set -l channels alpha beta stable
# MaaCore installer options
complete -c maa -n "__fish_seen_subcommand_from install update" -f -a "$channels" -d 'Channel of MaaCore to install'
complete -c maa -n "__fish_seen_subcommand_from install update" -s t -l test-time -d 'Time to test download speed' -r
complete -c maa -n "__fish_seen_subcommand_from install update" -l no-resource -d 'Do not install resource'
complete -c maa -n "__fish_seen_subcommand_from install update" -s h -l help -d 'Print help (see more with \'--help\')'
complete -c maa -n "__fish_seen_subcommand_from install update" -l api-url -d 'URL of api to get version information of MaaCore' -r
complete -c maa -n "__fish_seen_subcommand_from install update" -l no-resource -d 'Do not install resource of MaaCore'
complete -c maa -n "__fish_seen_subcommand_from install" -s f -l force -d 'Force to install even if the maa and resource already exists'
## Self
complete -c maa -n "__fish_seen_subcommand_from self" -f -a "update" -d 'Update maa-cli self'
complete -c maa -n "__fish_seen_subcommand_from self" -f -a "help" -d 'Print this message or the help of the given subcommand(s)'
complete -c maa -n "__fish_seen_subcommand_from self" -s h -l help -d 'Print help (see more with \'--help\')'
## Dir

# MaaCLI self update options
complete -c maa -n "__fish_seen_subcommand_from self; and not __fish_seen_subcommand_from update" -f -a "update" -d 'Install maa-cli self'
complete -c maa -n "__fish_seen_subcommand_from self; and __fish_seen_subcommand_from update" -a "$channels" -d 'Channel of maa-cli to install'
complete -c maa -n "__fish_seen_subcommand_from self; and __fish_seen_subcommand_from update" -l api-url -d 'URL of api to get version information of maa-cli' -r
complete -c maa -n "__fish_seen_subcommand_from self; and __fish_seen_subcommand_from update" -l download-url -d 'URL of maa-cli to download' -r

# Maa directory navigation
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "data" -d "Print maa-cli's data directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "lib" -d "Print MaaCore library directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "config" -d "Print maa-cli's config directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "cache" -d "Print maa-cli's cache directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "resource" -d "Print MaaCore's resource directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "hot-update" -d "Print MaaCore's hot-update directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -f -a "log" -d "Print MaaCore's log directory"
complete -c maa -n "__fish_seen_subcommand_from dir" -s h -l help -d 'Print help (see more with \'--help\')'
## Version
complete -c maa -n "__fish_seen_subcommand_from version" -f -a "all maa-cli maa-core" -d 'Print version of given component'
complete -c maa -n "__fish_seen_subcommand_from version" -s h -l help -d 'Print help (see more with \'--help\')'
## Run

# Maa run related options
## Common options
set -l run_commands run fight copilot roguelike
complete -c maa -n "__fish_seen_subcommand_from $run_commands" -s a -l addr -d 'ADB serial number of device or MaaTools address set in PlayCover' -r
complete -c maa -n "__fish_seen_subcommand_from $run_commands" -l user-resource -d 'Load resources from the config directory'
complete -c maa -n "__fish_seen_subcommand_from $run_commands" -l dry-run -d 'Parse the your config but do not connect to the game'
## command specific options
complete -c maa -n "__fish_seen_subcommand_from run" -f -a "$(maa list)"
complete -c maa -n "__fish_seen_subcommand_from run" -s a -l addr -d 'ADB serial number of device or MaaTools address set in PlayCover' -r
complete -c maa -n "__fish_seen_subcommand_from run" -s v -l verbose -d 'Output more information, repeat to increase verbosity'
complete -c maa -n "__fish_seen_subcommand_from run" -s q -l quiet -d 'Output less information, repeat to increase quietness'
complete -c maa -n "__fish_seen_subcommand_from run" -s b -l batch -d 'Run task in batch mode without interaction'
complete -c maa -n "__fish_seen_subcommand_from run" -l user-resource -d 'Load resources from the user config directory'
complete -c maa -n "__fish_seen_subcommand_from run" -s h -l help -d 'Print help (see more with \'--help\')'
## Help
complete -c maa -n "__fish_seen_subcommand_from help" -f -a "install update self dir version run list complete" -d 'Print help of given subcommand(s)'
complete -c maa -n "__fish_seen_subcommand_from fight" -l startup -d 'Whether to start the game'
complete -c maa -n "__fish_seen_subcommand_from fight" -l closedown -d 'Whether to close the game'
complete -c maa -n "__fish_seen_subcommand_from roguelike" -a "phantom mizuki sami"

# Subcommand don't require arguments
complete -c maa -n "__fish_seen_subcommand_from hot-update list" -f # prevent fish complete from path
50 changes: 32 additions & 18 deletions maa-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct CLI {
/// See documentation of log level for more information.
#[arg(short, long, verbatim_doc_comment, action = clap::ArgAction::Count, global = true)]
quiet: u8,
/// Enable touch mode
/// Enable batch mode
///
/// If there are some input parameters in the task file,
/// some prompts will be displayed to ask for input.
Expand Down Expand Up @@ -114,7 +114,7 @@ enum SubCommand {
#[arg(default_value_t = Component::All)]
component: Component,
},
/// Run a predefined task
/// Run a custom task
///
/// All arguments will be passed to maa-run,
/// type --help to get more information.
Expand Down Expand Up @@ -190,7 +190,9 @@ enum SelfCommand {
enum Component {
#[default]
All,
#[value(alias("cli"))]
MaaCLI,
#[value(alias("core"))]
MaaCore,
}

Expand Down Expand Up @@ -506,30 +508,42 @@ mod test {

#[test]
fn version() {
assert!(matches!(
assert_matches!(
CLI::parse_from(["maa", "version"]).command,
SubCommand::Version {
component: Component::All
}
));
assert!(matches!(
);
assert_matches!(
CLI::parse_from(["maa", "version", "all"]).command,
SubCommand::Version {
component: Component::All
}
));
assert!(matches!(
);
assert_matches!(
CLI::parse_from(["maa", "version", "maa-cli"]).command,
SubCommand::Version {
component: Component::MaaCLI
}
));
assert!(matches!(
);
assert_matches!(
CLI::parse_from(["maa", "version", "cli"]).command,
SubCommand::Version {
component: Component::MaaCLI
}
);
assert_matches!(
CLI::parse_from(["maa", "version", "maa-core"]).command,
SubCommand::Version {
component: Component::MaaCore
}
));
);
assert_matches!(
CLI::parse_from(["maa", "version", "core"]).command,
SubCommand::Version {
component: Component::MaaCore
}
);
}

#[test]
Expand Down Expand Up @@ -580,35 +594,35 @@ mod test {

#[test]
fn fight() {
assert!(matches!(
assert_matches!(
CLI::parse_from(["maa", "fight"]).command,
SubCommand::Fight {
stage: None,
startup: false,
closedown: false,
..
}
));
);

assert!(matches!(
assert_matches!(
CLI::parse_from(["maa", "fight", "1-7"]).command,
SubCommand::Fight {
stage: Some(stage),
..
} if stage == "1-7"
));
);

assert!(matches!(
assert_matches!(
CLI::parse_from(["maa", "fight", "--startup"]).command,
SubCommand::Fight { startup: true, .. }
));
assert!(matches!(
);
assert_matches!(
CLI::parse_from(["maa", "fight", "--closedown"]).command,
SubCommand::Fight {
closedown: true,
..
}
));
);
}

#[test]
Expand Down

0 comments on commit e809692

Please sign in to comment.