Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update clasp completion #10377

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
213 changes: 140 additions & 73 deletions share/completions/clasp.fish
Original file line number Diff line number Diff line change
@@ -1,104 +1,171 @@
function __fish_clasp_list_projects
clasp list --noShorten true 2>/dev/null |
string replace --regex '(.*) - https://script.google.com/d/(.*)/edit' '$2\\t$1'
end

function __fish_clasp_list_versions
clasp versions 2>/dev/null |
string replace --regex '(\\d+) - (.*)' '$1\\t$2' |
sed -n '2,$p'
end

function __fish_clasp_list_deployments
clasp deployments 2>/dev/null |
string replace --regex -- '- (\\S+) @(\\S+).*' '$1\\tversion $2' |
sed -n '2,$p'
end

function __fish_list_advanced_services
printf '%s\\t%s service\n' admin-sdk-directory 'Admin SDK Directory' \
admin-sdk-license-manager 'Admin SDK Enterprise License Manager' \
admin-sdk-groups-migration 'Admin SDK Groups Migration' \
admin-sdk-groups-settings 'Admin SDK Groups Settings' \
admin-sdk-reseller 'Admin SDK Google Workspace Reseller' \
admin-sdk-reports 'Admin SDK Reports' \
calendar 'Advanced Calendar' \
chat 'Advanced Chat' \
docs 'Advanced Docs' \
drive 'Advanced Drive' \
drive-activity 'Google Drive Activity' \
drive-labels 'Advanced Drive Labels' \
gmail 'Advanced Gmail' \
sheets 'Advanced Sheets' \
slides 'Advanced Slides' \
classroom Classroom \
people 'Advanced People' \
contacts-people 'Migrate from Contacts service to People API' \
tasks Tasks
end

function __fish_clasp_list_functions
grep --extended-regexp '^\\s*function\\s+\\w+' --recursive --include '*.js' --no-filename --color=never . |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some implementations of grep don't support --include or --color.
It's probably not relevant to most users of clasp so I don't think this is blocking.. I think we can find a better solution anyway

I think it would be preferrable to add a command like clasp run --list-functions to output the list of available functions because they will know best.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also long options are a compatibility issue in general, see e.g. the OpenBSD man page - which supports some long options, but only for compatibility with GNU grep where no short option is available.

string replace --regex '\\s*function\\s+(\\w+).*' '$1'
end

function __fish_clasp_list_subcommands
clasp --help |
string match --regex '^ [a-z]' --entire |
string replace --regex '^\\s{2}([a-z]+).*' '$1'
end

function __fish_seen_subcommands_from
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

__fish_seen_subcommands_from has a name clash.
If the generic one doesn't work for some reason, it's fine to pu it into clasp.fish but use the __fish_clasp prefix if you do that.
Else things will behave differently depending on which completion script happens to be loaded first.

set -l cmd (commandline -poc)
set -e cmd[1]

test (count $argv) -gt (count $cmd) && return 1

set -l i (count $argv)
set -l j (count $cmd)
while test $i -gt 0
contains -- $argv[$i] $cmd[$j] || return 1
set i (math $i - 1)
set j (math $j - 1)
end

return 0
end

# options
complete -c clasp -s v -l version -d "output the current version"
complete -c clasp -s A -l auth -d "path to an auth file or a folder with a '.clasprc.json' file."
complete -c clasp -s I -l ignore -d "path to an ignore file or a folder with a '.claspignore' file."
complete -c clasp -s P -l project -d "path to a project file or to a folder with a '.clasp.json' file."
complete -c clasp -s W -l why -d "Display some debugging info upon exit."
complete -c clasp -s h -l help -d "display help for command"
complete -c clasp -s h -l help -d 'Show [h]elp'
complete -c clasp -s v -l version -d 'Show [v]ersion'

complete -c clasp -s A -l auth -d "Path to a '.clasprc.json' or to a directory with it"
complete -c clasp -s I -l ignore -d "Path to a '.claspignore.json' or to a directory with it"
complete -c clasp -s P -l project -d "Path to a '.clasp.json' or to a directory with it"
complete -c clasp -s W -l why -d "Display some debugging info upon exit"

# subcommands
complete -f -c clasp -n __fish_use_subcommand -xa login -d "Log in to script.google.com"
complete -f -c clasp -n __fish_use_subcommand -xa logout -d "Log out"
complete -f -c clasp -n __fish_use_subcommand -xa create -d "Create a script"
complete -f -c clasp -n __fish_use_subcommand -xa clone -d "Clone a project"
complete -f -c clasp -n __fish_use_subcommand -xa pull -d "Fetch a remote project"
complete -f -c clasp -n __fish_use_subcommand -xa push -d "Update the remote project"
complete -f -c clasp -n __fish_use_subcommand -xa status -d "Lists files that will be pushed by clasp"
complete -f -c clasp -n __fish_use_subcommand -xa open -d "Open a script"
complete -f -c clasp -n __fish_use_subcommand -xa deployments -d "List deployment ids of a script"
complete -f -c clasp -n __fish_use_subcommand -xa deploy -d "Deploy a project"
complete -f -c clasp -n __fish_use_subcommand -xa undeploy -d "Undeploy a deployment of a project"
complete -f -c clasp -n __fish_use_subcommand -xa version -d "Creates an immutable version of the script"
complete -f -c clasp -n __fish_use_subcommand -xa versions -d "List versions of a script"
complete -f -c clasp -n __fish_use_subcommand -xa list -d "List App Scripts projects"
complete -f -c clasp -n __fish_use_subcommand -xa logs -d "Shows the StackDriver logs"
complete -f -c clasp -n __fish_use_subcommand -xa run -d "Run a function in your Apps Scripts project"
complete -f -c clasp -n __fish_use_subcommand -xa apis -d "List, enable, or disable APIs"
complete -f -c clasp -n __fish_use_subcommand -xa help -d "display help for command"
complete -c clasp -n __fish_use_subcommand -x -a login -d "Log in to script.google.com"
complete -c clasp -n __fish_use_subcommand -x -a logout -d "Log out"
complete -c clasp -n __fish_use_subcommand -x -a create -d "Create a script"
complete -c clasp -n __fish_use_subcommand -x -a clone -d "Clone a project"
complete -c clasp -n __fish_use_subcommand -x -a pull -d "Fetch a remote project"
complete -c clasp -n __fish_use_subcommand -x -a push -d "Update the remote project"
complete -c clasp -n __fish_use_subcommand -x -a status -d "Lists files that will be pushed by 'push' subcommand"
complete -c clasp -n __fish_use_subcommand -x -a open -d "Open a script"
complete -c clasp -n __fish_use_subcommand -x -a deployments -d "List deployment IDs of a script"
complete -c clasp -n __fish_use_subcommand -x -a deploy -d "Deploy a project"
complete -c clasp -n __fish_use_subcommand -x -a undeploy -d "Undeploy a project"
complete -c clasp -n __fish_use_subcommand -x -a version -d "Create an immutable version of a script"
complete -c clasp -n __fish_use_subcommand -x -a versions -d "List versions of a script"
complete -c clasp -n __fish_use_subcommand -x -a list -d "List projects"
complete -c clasp -n __fish_use_subcommand -x -a logs -d "Show StackDriver logs"
complete -c clasp -n __fish_use_subcommand -x -a run -d "Run a function in your Apps Scripts project"
complete -c clasp -n __fish_use_subcommand -x -a apis -d "List, enable, or disable APIs"
complete -c clasp -n __fish_use_subcommand -x -a help -d "Show help for a command"

# login options
complete -c clasp -n '__fish_seen_subcommand_from login' -l no-localhost -d 'Do not run a local server, manually enter code instead'
complete -c clasp -n '__fish_seen_subcommand_from login' -l creds -d 'Relative path to credentials (from GCP).'
complete -c clasp -n '__fish_seen_subcommand_from login' -l status -d 'Print who is logged in'
set login_condition '__fish_seen_subcommand_from login'
complete -c clasp -n "$login_condition" -l no-localhost -d 'Do not run a local server, manually enter code instead'
complete -c clasp -n "$login_condition" -l creds -d 'Specify a relative path to credentials'
complete -c clasp -n "$login_condition" -l status -d 'Show who is logged in'

# create option
complete -c clasp -n '__fish_seen_subcommand_from create' -l type -d "Creates a new Apps Script project attached to a new Document, Spreadsheet, Presentation, Form, or as a standalone script, web app, or API."
complete -c clasp -n '__fish_seen_subcommand_from create' -l parentId -d "A project parent Id."
complete -c clasp -n '__fish_seen_subcommand_from create' -l rootDir -d "Local root directory in which clasp will store your project files."
set create_condition '__fish_seen_subcommand_from create'
complete -c clasp -n "$create_condition" -l type -x -a 'standalone docs sheets slides forms webapp api' -d "A project type"
complete -c clasp -n "$create_condition" -l title -d "A project title"
complete -c clasp -n "$create_condition" -l parentId -d "A project container ID"
complete -c clasp -n "$create_condition" -l rootDir -d "Path to a directory with project files"

# clone options
complete -c clasp -n '__fish_seen_subcommand_from clone' -l rootDir -d "Local root directory in which clasp will store your project files."
set clone_condition '__fish_seen_subcommand_from clone'
complete -c clasp -n "$clone_condition" -l rootDir -d "Path to a directory project files"
complete -c clasp -n "$clone_condition" -x -a '(__fish_clasp_list_projects)'

# pull options
complete -c clasp -n '__fish_seen_subcommand_from pull' -l versionNumber -d "The version number of the project to retrieve."
complete -c clasp -n '__fish_seen_subcommand_from pull' -l versionNumber -x -a '(__fish_clasp_list_versions)' -d "A project version to pull"

# push options
complete -c clasp -n '__fish_seen_subcommand_from push' -s f -l force -d "Forcibly overwrites the remote manifest."
complete -c clasp -n '__fish_seen_subcommand_from push' -s w -l watch -d "Watches for local file changes. Pushes when a non-ignored file changes."
set push_condition '__fish_seen_subcommand_from push'
complete -c clasp -n "$push_condition" -s f -l force -d "Forcibly overwrite a remote manifest"
complete -c clasp -n "$push_condition" -s w -l watch -d "Watch for local changes in non-ignored files and push when they occur"

# status options
complete -c clasp -n '__fish_seen_subcommand_from status' -l json -d "Show status in JSON form"
complete -c clasp -n '__fish_seen_subcommand_from status' -l json -d "Show in JSON format"

# open options
complete -c clasp -n '__fish_seen_subcommand_from open' -l webapp -d "Open web application in the browser"
complete -c clasp -n '__fish_seen_subcommand_from open' -l creds -d "Open the URL to create credentials"
complete -c clasp -n '__fish_seen_subcommand_from open' -l addon -d "List parent IDs and open the URL of the first one"
complete -c clasp -n '__fish_seen_subcommand_from open' -l deploymentId -d "Use custom deployment ID with webapp"
set open_condition '__fish_seen_subcommand_from open'
complete -c clasp -n "$open_condition" -l webapp -d "Open a web application in a browser"
complete -c clasp -n "$open_condition" -l creds -d "Open the URL to create credentials"
complete -c clasp -n "$open_condition" -l addon -d "List parent IDs and open the URL of the first one"
complete -c clasp -n "$open_condition" -l deploymentId -d "Use a custom deployment ID with a web application"

# deploy options
complete -c clasp -n '__fish_seen_subcommand_from deploy' -s V -l versionNumber -d "The project version"
complete -c clasp -n '__fish_seen_subcommand_from deploy' -s d -l description -d "The deployment description"
complete -c clasp -n '__fish_seen_subcommand_from deploy' -s i -l deploymentId -d "The deployment ID to redeploy"
set deploy_condition '__fish_seen_subcommand_from deploy'
complete -c clasp -n "$deploy_condition" -s V -l versionNumber -d "A project version"
complete -c clasp -n "$deploy_condition" -s d -l description -d "A deployment description"
complete -c clasp -n "$deploy_condition" -s i -l deploymentId -x -a '(__fish_clasp_list_deployments)' -d "A deployment ID to redeploy"

# undeploy options
complete -c clasp -n '__fish_seen_subcommand_from undeploy' -l all -d "Undeploy all deployments"
complete -c clasp -n '__fish_seen_subcommand_from undeploy' -l help -d "display help for command"
set undeploy_condition '__fish_seen_subcommand_from undeploy'
complete -c clasp -n "$undeploy_condition" -l all -d "Undeploy all deployments"
complete -c clasp -n "$undeploy_condition" -x -a '(__fish_clasp_list_deployments)'

# list options
complete -c clasp -n '__fish_seen_subcommand_from list' -l noShorten -d "Do not shorten long names (default: false)"
complete -c clasp -n '__fish_seen_subcommand_from list' -l noShorten -d "Do not shorten long names"

# logs options
complete -c clasp -n '__fish_seen_subcommand_from logs' -l json -d "Show logs in JSON form"
complete -c clasp -n '__fish_seen_subcommand_from logs' -l open -d "Open the StackDriver logs in the browser"
complete -c clasp -n '__fish_seen_subcommand_from logs' -l setup -d "Setup StackDriver logs"
complete -c clasp -n '__fish_seen_subcommand_from logs' -l watch -d "Watch and print new logs"
complete -c clasp -n '__fish_seen_subcommand_from logs' -l simplified -d "Hide timestamps with logs"
set logs_condition '__fish_seen_subcommand_from logs'
complete -c clasp -n "$logs_condition" -l json -d "Show logs in JSON form"
complete -c clasp -n "$logs_condition" -l open -d "Open the StackDriver logs in a browser"
complete -c clasp -n "$logs_condition" -l setup -d "Setup StackDriver logs"
complete -c clasp -n "$logs_condition" -l watch -d "Watch and list new logs"
complete -c clasp -n "$logs_condition" -l simplified -d "Hide timestamps with logs"

# run options
complete -c clasp -n '__fish_seen_subcommand_from run' -l nondev -d "Run script function in non-devMode"
complete -c clasp -n '__fish_seen_subcommand_from run' -s p -l params -d "Add parameters required for the function as a JSON String Array"
set run_condition '__fish_seen_subcommand_from run'
complete -c clasp -n "$run_condition" -l nondev -d "Run a function in non-development mode"
complete -c clasp -n "$run_condition" -s p -l params -d "Specify parameters for a function as a JSON array"
complete -c clasp -n "$run_condition" -x -a '(__fish_clasp_list_functions)'

# apis subcommands and options
complete -c clasp -n '__fish_seen_subcommand_from apis' -xa list
complete -c clasp -n '__fish_seen_subcommand_from apis' -xa enable
complete -c clasp -n '__fish_seen_subcommand_from apis' -xa disable
complete -c clasp -n '__fish_seen_subcommand_from apis' -l open -d "Open the API Console in the browser"
set apis_condition '__fish_seen_subcommand_from apis'
set apis_subcommand_condition '__fish_seen_subcommands_from apis enable || __fish_seen_subcommands_from apis disable'
complete -c clasp -n "$apis_condition" -x -a list -d 'List APIs'
complete -c clasp -n "$apis_condition" -x -a enable -d 'Enable APIs'
complete -c clasp -n "$apis_condition" -x -a disable -d 'Disable APIs'
complete -c clasp -n "$apis_condition" -l open -d "Open API Console in a browser"
complete -c clasp -n "$apis_subcommand_condition" -a '(__fish_list_advanced_services)'

# help subcommands
complete -c clasp -n '__fish_seen_subcommand_from help' -xa login
complete -c clasp -n '__fish_seen_subcommand_from help' -xa logout
complete -c clasp -n '__fish_seen_subcommand_from help' -xa create
complete -c clasp -n '__fish_seen_subcommand_from help' -xa clone
complete -c clasp -n '__fish_seen_subcommand_from help' -xa pull
complete -c clasp -n '__fish_seen_subcommand_from help' -xa push
complete -c clasp -n '__fish_seen_subcommand_from help' -xa status
complete -c clasp -n '__fish_seen_subcommand_from help' -xa open
complete -c clasp -n '__fish_seen_subcommand_from help' -xa deployments
complete -c clasp -n '__fish_seen_subcommand_from help' -xa deploy
complete -c clasp -n '__fish_seen_subcommand_from help' -xa undeploy
complete -c clasp -n '__fish_seen_subcommand_from help' -xa version
complete -c clasp -n '__fish_seen_subcommand_from help' -xa versions
complete -c clasp -n '__fish_seen_subcommand_from help' -xa list
complete -c clasp -n '__fish_seen_subcommand_from help' -xa logs
complete -c clasp -n '__fish_seen_subcommand_from help' -xa run
complete -c clasp -n '__fish_seen_subcommand_from help' -xa apis
complete -c clasp -n '__fish_seen_subcommand_from help' -x -a '(__fish_clasp_list_subcommands)'