forked from heroku/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(autocomplete): add autocomplete plugin to monorepo (heroku#937)
- Loading branch information
Showing
38 changed files
with
4,620 additions
and
0 deletions.
There are no files selected for viewing
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,42 @@ | ||
--- | ||
version: 2 | ||
jobs: | ||
node-latest: &test | ||
docker: | ||
- image: node:latest | ||
working_directory: ~/cli | ||
steps: | ||
- checkout | ||
- restore_cache: &restore_cache | ||
keys: | ||
- v1-npm-{{checksum ".circleci/config.yml"}}-{{ checksum "yarn.lock"}} | ||
- v1-npm-{{checksum ".circleci/config.yml"}} | ||
- run: | ||
name: Install dependencies | ||
command: .circleci/greenkeeper | ||
- run: ./bin/run --help | ||
- run: | ||
name: Testing | ||
command: yarn test | ||
- run: | ||
name: Submitting code coverage to codecov | ||
command: | | ||
./node_modules/.bin/nyc report --reporter text-lcov > coverage.lcov | ||
curl -s https://codecov.io/bash | bash | ||
- save_cache: | ||
key: v1-yarn-{{checksum ".circleci/config.yml"}}-{{checksum "yarn.lock"}} | ||
paths: | ||
- ~/cli/node_modules | ||
- /usr/local/share/.cache/yarn | ||
- /usr/local/share/.config/yarn | ||
node-8: | ||
<<: *test | ||
docker: | ||
- image: node:8 | ||
|
||
workflows: | ||
version: 2 | ||
"@heroku-cli/plugin-autocomplete": | ||
jobs: | ||
- node-latest | ||
- node-8 |
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,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -ex | ||
|
||
PATH=/usr/local/share/.config/yarn/global/node_modules/.bin:$PATH | ||
|
||
if [[ "$CIRCLE_BRANCH" != greenkeeper/* ]]; then | ||
yarn | ||
# yarn check | ||
exit 0 | ||
fi | ||
|
||
if [[ ! -z "$GIT_EMAIL" ]] & [[ ! -z "$GIT_USERNAME" ]]; then | ||
git config --global push.default simple | ||
git config --global user.email "$GIT_EMAIL" | ||
git config --global user.name "$GIT_USERNAME" | ||
fi | ||
|
||
if [[ ! -x "$(command -v greenkeeper-lockfile-update)" ]]; then | ||
yarn global add greenkeeper-lockfile@1 | ||
fi | ||
|
||
greenkeeper-lockfile-update | ||
yarn | ||
greenkeeper-lockfile-upload |
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,11 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,3 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
*.ts text eol=lf |
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,9 @@ | ||
*-debug.log | ||
*-error.log | ||
.oclif.manifest.json | ||
/.nyc_output | ||
/dist | ||
/lib | ||
/package-lock.json | ||
/tmp | ||
node_modules |
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,12 @@ | ||
{ | ||
"extension": [ | ||
".ts" | ||
], | ||
"include": [ | ||
"src/**/*.ts" | ||
], | ||
"exclude": [ | ||
"**/*.d.ts" | ||
], | ||
"all": true | ||
} |
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 @@ | ||
* @heroku/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Salesforce.com | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,52 @@ | ||
@heroku-cli/plugin-autocomplete | ||
=============================== | ||
|
||
|
||
|
||
[](https://npmjs.org/package/@heroku-cli/plugin-autocomplete) | ||
[](https://circleci.com/gh/heroku/heroku-cli-autocomplete/tree/master) | ||
[](https://ci.appveyor.com/project/heroku/heroku-cli-autocomplete/branch/master) | ||
[](https://codecov.io/gh/heroku/heroku-cli-autocomplete) | ||
[](https://npmjs.org/package/@heroku-cli/plugin-autocomplete) | ||
[](https://github.com/heroku/heroku-cli-autocomplete/blob/master/package.json) | ||
|
||
<!-- toc --> | ||
* [Usage](#usage) | ||
* [Commands](#commands) | ||
<!-- tocstop --> | ||
# Usage | ||
<!-- usage --> | ||
```sh-session | ||
$ heroku update | ||
$ heroku plugins:install autocomplete | ||
$ heroku autocomplete | ||
``` | ||
<!-- usagestop --> | ||
# Commands | ||
<!-- commands --> | ||
* [`heroku autocomplete [SHELL]`](#heroku-autocomplete-shell) | ||
|
||
## `heroku autocomplete [SHELL]` | ||
|
||
display autocomplete installation instructions | ||
|
||
``` | ||
USAGE | ||
$ heroku autocomplete [SHELL] | ||
ARGUMENTS | ||
SHELL shell type | ||
OPTIONS | ||
-s, --skip-instructions don't show installation instructions | ||
EXAMPLES | ||
$ heroku autocomplete | ||
$ heroku autocomplete bash | ||
$ heroku autocomplete zsh | ||
``` | ||
|
||
_See code: [src/commands/autocomplete/index.ts](https://github.com/heroku/heroku-cli-autocomplete/blob/master/src/commands/autocomplete/index.ts)_ | ||
<!-- commandsstop --> |
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,21 @@ | ||
environment: | ||
nodejs_version: "9" | ||
cache: | ||
- '%LOCALAPPDATA%\Yarn -> appveyor.yml' | ||
- node_modules -> yarn.lock | ||
|
||
install: | ||
- ps: Install-Product node $env:nodejs_version x64 | ||
- yarn | ||
test_script: | ||
- .\bin\run --help | ||
- yarn test | ||
after_test: | ||
- .\node_modules\.bin\nyc report --reporter text-lcov > coverage.lcov | ||
- ps: | | ||
$env:PATH = 'C:\msys64\usr\bin;' + $env:PATH | ||
Invoke-WebRequest -Uri 'https://codecov.io/bash' -OutFile codecov.sh | ||
bash codecov.sh | ||
build: off | ||
|
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,59 @@ | ||
#!/usr/bin/env bash | ||
|
||
if ! type __ltrim_colon_completions >/dev/null 2>&1; then | ||
# Copyright © 2006-2008, Ian Macdonald <[email protected]> | ||
# © 2009-2017, Bash Completion Maintainers | ||
__ltrim_colon_completions() { | ||
# If word-to-complete contains a colon, | ||
# and bash-version < 4, | ||
# or bash-version >= 4 and COMP_WORDBREAKS contains a colon | ||
if [[ | ||
"$1" == *:* && ( | ||
${BASH_VERSINFO[0]} -lt 4 || | ||
(${BASH_VERSINFO[0]} -ge 4 && "$COMP_WORDBREAKS" == *:*) | ||
) | ||
]]; then | ||
# Remove colon-word prefix from COMPREPLY items | ||
local colon_word=${1%${1##*:}} | ||
local i=${#COMPREPLY[*]} | ||
while [ $((--i)) -ge 0 ]; do | ||
COMPREPLY[$i]=${COMPREPLY[$i]#"$colon_word"} | ||
done | ||
fi | ||
} | ||
fi | ||
|
||
_compreply_cli () { | ||
opts=("$(heroku autocomplete:options "$(echo "${COMP_WORDS[*]}")")") | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
} | ||
|
||
_heroku() | ||
{ | ||
# print error and exit if vars are not set | ||
: "${HEROKU_AC_ANALYTICS_DIR?}" | ||
: "${HEROKU_AC_COMMANDS_PATH?}" | ||
|
||
local cur="${COMP_WORDS[COMP_CWORD]}" opts IFS=$' \t\n' | ||
COMPREPLY=() | ||
mkdir -p "$HEROKU_AC_ANALYTICS_DIR" | ||
|
||
if [[ "${COMP_CWORD}" -eq 1 ]] ; then | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/command | ||
opts=$(grep -oe '^[a-zA-Z0-9:_-]\+' $HEROKU_AC_COMMANDS_PATH) | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
__ltrim_colon_completions "$cur" | ||
else | ||
if [[ $cur == "-"* ]] ; then | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/flag | ||
opts=$(grep "${COMP_WORDS[1]}" $HEROKU_AC_COMMANDS_PATH | sed -n "s/^${COMP_WORDS[1]} //p") | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
else | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/value | ||
_compreply_cli | ||
fi | ||
fi | ||
return 0 | ||
} | ||
|
||
complete -F _heroku heroku |
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,53 @@ | ||
#compdef heroku | ||
|
||
_heroku () { | ||
# exit if vars are not set | ||
: "${HEROKU_AC_ANALYTICS_DIR?}" | ||
: "${HEROKU_AC_COMMANDS_PATH?}" | ||
|
||
local -a _flags=() | ||
local _command_id=${words[2]} | ||
local _cur=${words[CURRENT]} | ||
|
||
mkdir -p "$HEROKU_AC_ANALYTICS_DIR" | ||
|
||
## all commands | ||
_complete_commands () { | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/command | ||
local -a _all_commands_list | ||
if type _set_all_commands_list >/dev/null 2>&1; then | ||
_set_all_commands_list | ||
_describe -t all-commands "all commands" _all_commands_list | ||
return | ||
fi | ||
# fallback to grep'ing cmds from cache | ||
compadd $(grep -oe '^[a-zA-Z0-9:_-]\+' $HEROKU_AC_COMMANDS_PATH) | ||
} | ||
## end all commands | ||
|
||
_compadd_args () { | ||
compadd $(echo $([[ -n $REPORTTIME ]] && REPORTTIME=100; heroku autocomplete:options "${words}")) | ||
} | ||
|
||
_compadd_flag_options () { | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/value | ||
_compadd_args | ||
} | ||
|
||
if [ $CURRENT -gt 2 ]; then | ||
if [[ "$_cur" == -* ]]; then | ||
touch "$HEROKU_AC_ANALYTICS_DIR"/flag | ||
local _flag_completion_func="_set_${_command_id//:/_}_flags" | ||
declare -f $_flag_completion_func >/dev/null && $_flag_completion_func | ||
else | ||
if type _compadd_args >/dev/null 2>&1; then | ||
_compadd_args | ||
fi | ||
fi | ||
fi | ||
|
||
_arguments '1: :_complete_commands' \ | ||
$_flags | ||
} | ||
|
||
_heroku |
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,4 @@ | ||
#!/usr/bin/env node | ||
|
||
require('@oclif/command').run() | ||
.catch(require('@oclif/errors/handle')) |
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,3 @@ | ||
@echo off | ||
|
||
node "%~dp0\run" %* |
Oops, something went wrong.