diff --git a/crates/infra/cli/build.rs b/crates/infra/cli/build.rs index 7a114e715d..2b659f4f30 100644 --- a/crates/infra/cli/build.rs +++ b/crates/infra/cli/build.rs @@ -10,22 +10,28 @@ use infra_utils::codegen::Codegen; include!("src/lib.rs"); fn main() -> Result<()> { - generate_completions(Shell::Zsh) + generate_completions(&[Shell::Zsh, Shell::Bash]) } /// Generate auto-completions for the shell. -fn generate_completions(shell: Shell) -> Result<()> { - let mut buffer = vec![]; +fn generate_completions(shells: &[Shell]) -> Result<()> { + let mut codegen = Codegen::write_only()?; let mut command = CLI::command(); command.build(); - shell.generate(&command, &mut buffer); + for shell in shells { + let mut buffer = vec![]; - let crate_dir = CargoWorkspace::locate_source_crate("infra_cli")?; + shell.generate(&command, &mut buffer); - Codegen::write_only()?.write_file( - crate_dir.join(format!("generated/infra.{shell}-completions")), - String::from_utf8(buffer)?, - ) + let crate_dir = CargoWorkspace::locate_source_crate("infra_cli")?; + + codegen.write_file( + crate_dir.join(format!("generated/infra.{shell}-completions")), + String::from_utf8(buffer)?, + )?; + } + + Ok(()) } diff --git a/crates/infra/cli/generated/infra.bash-completions b/crates/infra/cli/generated/infra.bash-completions new file mode 100644 index 0000000000..0519db6e95 --- /dev/null +++ b/crates/infra/cli/generated/infra.bash-completions @@ -0,0 +1,380 @@ +# This file is generated automatically by infrastructure scripts. Please don't edit by hand. + +_infra() { + local i cur prev opts cmd + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="" + opts="" + + for i in ${COMP_WORDS[@]} + do + case "${cmd},${i}" in + ",$1") + cmd="infra" + ;; + infra_cli,check) + cmd="infra_cli__check" + ;; + infra_cli,ci) + cmd="infra_cli__ci" + ;; + infra_cli,completions) + cmd="infra_cli__completions" + ;; + infra_cli,help) + cmd="infra_cli__help" + ;; + infra_cli,lint) + cmd="infra_cli__lint" + ;; + infra_cli,publish) + cmd="infra_cli__publish" + ;; + infra_cli,run) + cmd="infra_cli__run" + ;; + infra_cli,setup) + cmd="infra_cli__setup" + ;; + infra_cli,test) + cmd="infra_cli__test" + ;; + infra_cli,watch) + cmd="infra_cli__watch" + ;; + infra_cli__help,check) + cmd="infra_cli__help__check" + ;; + infra_cli__help,ci) + cmd="infra_cli__help__ci" + ;; + infra_cli__help,completions) + cmd="infra_cli__help__completions" + ;; + infra_cli__help,help) + cmd="infra_cli__help__help" + ;; + infra_cli__help,lint) + cmd="infra_cli__help__lint" + ;; + infra_cli__help,publish) + cmd="infra_cli__help__publish" + ;; + infra_cli__help,run) + cmd="infra_cli__help__run" + ;; + infra_cli__help,setup) + cmd="infra_cli__help__setup" + ;; + infra_cli__help,test) + cmd="infra_cli__help__test" + ;; + infra_cli__help,watch) + cmd="infra_cli__help__watch" + ;; + *) + ;; + esac + done + + case "${cmd}" in + infra) + opts="-h --help setup check test lint ci run watch publish completions help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__check) + opts="-h --help cargo rustdoc npm mkdocs" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__ci) + opts="-h --help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__completions) + opts="-h --help bash elvish fish powershell zsh" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help) + opts="setup check test lint ci run watch publish completions help" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__check) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__ci) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__completions) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__help) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__lint) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__publish) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__run) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__setup) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__test) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__help__watch) + opts="" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 3 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__lint) + opts="-h --help cspell prettier markdown-link-check markdown-lint rustfmt shellcheck tsc yamllint" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__publish) + opts="-h --help changesets npm cargo github-release lock-files" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__run) + opts="-h --help slang_solidity solidity_testing_sanctuary solidity_testing_solc solidity_cargo_build solidity_npm_build [ARGS]..." + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__setup) + opts="-h --help cargo npm pipenv" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__test) + opts="-h --help cargo npm" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + infra__watch) + opts="-h --help mkdocs" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 2 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac +} + +complete -F _infra -o bashdefault -o default infra diff --git a/crates/infra/utils/src/codegen/common/formatting.rs b/crates/infra/utils/src/codegen/common/formatting.rs index 0909a816f5..cee3324d6c 100644 --- a/crates/infra/utils/src/codegen/common/formatting.rs +++ b/crates/infra/utils/src/codegen/common/formatting.rs @@ -29,7 +29,7 @@ fn generate_header(file_path: &Path) -> String { "json" => String::new(), "html" | "md" => format!(""), "js" | "rs" | "ts" => format!("// {warning_line}"), - "yml" | "zsh-completions" => format!("# {warning_line}"), + "yml" | "zsh-completions" | "bash-completions" => format!("# {warning_line}"), ext => panic!("Unsupported extension to generate a header for: {ext}"), }; } @@ -52,7 +52,7 @@ fn run_formatter(file_path: &Path, contents: &str) -> Result { // We already generate formatted content for these, so no need to run expensive formatting. Ok(contents.to_owned()) } - "ebnf" | "zsh-completions" => { + "ebnf" | "zsh-completions" | "bash-completions" => { // No formatters available for these (yet). Ok(contents.to_owned()) }