Skip to content

Commit

Permalink
feat(autocomplete): add autocomplete plugin to monorepo (heroku#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
RasPhilCo authored Jul 16, 2018
1 parent e8f7e4b commit a0d6794
Showing 38 changed files with 4,620 additions and 0 deletions.
42 changes: 42 additions & 0 deletions packages/autocomplete/.circleci/config.yml
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
25 changes: 25 additions & 0 deletions packages/autocomplete/.circleci/greenkeeper
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
11 changes: 11 additions & 0 deletions packages/autocomplete/.editorconfig
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
3 changes: 3 additions & 0 deletions packages/autocomplete/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* text=auto
*.js text eol=lf
*.ts text eol=lf
9 changes: 9 additions & 0 deletions packages/autocomplete/.gitignore
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
12 changes: 12 additions & 0 deletions packages/autocomplete/.nycrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extension": [
".ts"
],
"include": [
"src/**/*.ts"
],
"exclude": [
"**/*.d.ts"
],
"all": true
}
1 change: 1 addition & 0 deletions packages/autocomplete/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @heroku/cli
21 changes: 21 additions & 0 deletions packages/autocomplete/LICENSE
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.
52 changes: 52 additions & 0 deletions packages/autocomplete/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@heroku-cli/plugin-autocomplete
===============================



[![Version](https://img.shields.io/npm/v/@heroku-cli/plugin-autocomplete.svg)](https://npmjs.org/package/@heroku-cli/plugin-autocomplete)
[![CircleCI](https://circleci.com/gh/heroku/heroku-cli-autocomplete/tree/master.svg?style=shield)](https://circleci.com/gh/heroku/heroku-cli-autocomplete/tree/master)
[![Appveyor CI](https://ci.appveyor.com/api/projects/status/github/heroku/heroku-cli-autocomplete?branch=master&svg=true)](https://ci.appveyor.com/project/heroku/heroku-cli-autocomplete/branch/master)
[![Codecov](https://codecov.io/gh/heroku/heroku-cli-autocomplete/branch/master/graph/badge.svg)](https://codecov.io/gh/heroku/heroku-cli-autocomplete)
[![Downloads/week](https://img.shields.io/npm/dw/@heroku-cli/plugin-autocomplete.svg)](https://npmjs.org/package/@heroku-cli/plugin-autocomplete)
[![License](https://img.shields.io/npm/l/@heroku-cli/plugin-autocomplete.svg)](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 -->
21 changes: 21 additions & 0 deletions packages/autocomplete/appveyor.yml
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

59 changes: 59 additions & 0 deletions packages/autocomplete/autocomplete/bash/heroku.bash
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
53 changes: 53 additions & 0 deletions packages/autocomplete/autocomplete/zsh/_heroku
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
4 changes: 4 additions & 0 deletions packages/autocomplete/bin/run
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'))
3 changes: 3 additions & 0 deletions packages/autocomplete/bin/run.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\run" %*
Loading
Oops, something went wrong.

0 comments on commit a0d6794

Please sign in to comment.