mirror of
https://github.com/spf13/cobra
synced 2025-05-05 12:57:22 +00:00
Merge remote-tracking branch 'upstream/main' into InitDefaultCompletionCmd
This commit is contained in:
commit
d14b7bbec8
83 changed files with 3785 additions and 5127 deletions
12
.github/dependabot.yml
vendored
Normal file
12
.github/dependabot.yml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: gomod
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
open-pull-requests-limit: 99
|
||||||
|
- package-ecosystem: github-actions
|
||||||
|
directory: /
|
||||||
|
schedule:
|
||||||
|
interval: weekly
|
||||||
|
open-pull-requests-limit: 99
|
13
.github/labeler.yml
vendored
13
.github/labeler.yml
vendored
|
@ -1,16 +1,17 @@
|
||||||
# changes to documentation generation
|
# changes to documentation generation
|
||||||
"area/doc-gen": doc/**/*
|
"area/docs-generation": doc/**/*
|
||||||
|
|
||||||
# changes to the core Go cobra lib package
|
# changes to the core cobra command
|
||||||
"area/lib": ./*.go
|
"area/cobra-command":
|
||||||
|
- any: ['./cobra.go', './cobra_test.go', './*command*.go']
|
||||||
|
|
||||||
# changes to the Cobra CLI
|
# changes made to command flags/args
|
||||||
"area/cli": cobra/**/*
|
"area/flags": ./args*.go
|
||||||
|
|
||||||
# changes to Github workflows
|
# changes to Github workflows
|
||||||
"area/github": .github/**/*
|
"area/github": .github/**/*
|
||||||
|
|
||||||
# changes to shell completions
|
# changes to shell completions
|
||||||
"area/*sh completion":
|
"area/shell-completion":
|
||||||
- ./*completions*
|
- ./*completions*
|
||||||
|
|
||||||
|
|
83
.github/workflows/Test.yml
vendored
83
.github/workflows/Test.yml
vendored
|
@ -1,83 +0,0 @@
|
||||||
name: Test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
pull_request:
|
|
||||||
|
|
||||||
env:
|
|
||||||
GO111MODULE: on
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
|
|
||||||
|
|
||||||
test-unix:
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
matrix:
|
|
||||||
platform:
|
|
||||||
- ubuntu
|
|
||||||
- macOS
|
|
||||||
go:
|
|
||||||
- 1.14.x
|
|
||||||
- 1.15.x
|
|
||||||
name: '${{ matrix.platform }} | ${{ matrix.go }}'
|
|
||||||
runs-on: ${{ matrix.platform }}-latest
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- uses: actions/setup-go@v2
|
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go }}
|
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-${{ matrix.go }}-
|
|
||||||
|
|
||||||
- run: |
|
|
||||||
export GOBIN=$HOME/go/bin
|
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $GOBIN latest
|
|
||||||
go install github.com/kyoh86/richgo
|
|
||||||
go install github.com/mitchellh/gox
|
|
||||||
|
|
||||||
- run: PATH=$HOME/go/bin/:$PATH make
|
|
||||||
|
|
||||||
|
|
||||||
test-win:
|
|
||||||
name: MINGW64
|
|
||||||
defaults:
|
|
||||||
run:
|
|
||||||
shell: msys2 {0}
|
|
||||||
runs-on: windows-latest
|
|
||||||
steps:
|
|
||||||
|
|
||||||
- shell: bash
|
|
||||||
run: git config --global core.autocrlf input
|
|
||||||
|
|
||||||
- uses: msys2/setup-msys2@v2
|
|
||||||
with:
|
|
||||||
msystem: MINGW64
|
|
||||||
update: true
|
|
||||||
install: >
|
|
||||||
git
|
|
||||||
make
|
|
||||||
unzip
|
|
||||||
mingw-w64-x86_64-go
|
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: ~/go/pkg/mod
|
|
||||||
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
|
|
||||||
restore-keys: ${{ runner.os }}-${{ matrix.go }}-
|
|
||||||
|
|
||||||
- run: |
|
|
||||||
export GOBIN=$HOME/go/bin
|
|
||||||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | bash -s -- -b $GOBIN latest
|
|
||||||
go install github.com/kyoh86/richgo@latest
|
|
||||||
go install github.com/mitchellh/gox@latest
|
|
||||||
|
|
||||||
- run: PATH=$HOME/go/bin:$PATH make
|
|
8
.github/workflows/labeler.yml
vendored
8
.github/workflows/labeler.yml
vendored
|
@ -2,11 +2,17 @@ name: "Pull Request Labeler"
|
||||||
on:
|
on:
|
||||||
- pull_request_target
|
- pull_request_target
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
triage:
|
triage:
|
||||||
|
permissions:
|
||||||
|
contents: read # for actions/labeler to determine modified files
|
||||||
|
pull-requests: write # for actions/labeler to add labels to PRs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/labeler@v3
|
- uses: actions/labeler@v4
|
||||||
with:
|
with:
|
||||||
repo-token: "${{ github.token }}"
|
repo-token: "${{ github.token }}"
|
||||||
|
|
||||||
|
|
33
.github/workflows/size-labeler.yml
vendored
Normal file
33
.github/workflows/size-labeler.yml
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# Reference: https://github.com/CodelyTV/pr-size-labeler
|
||||||
|
|
||||||
|
name: size-labeler
|
||||||
|
|
||||||
|
on: [pull_request_target]
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
size-labeler:
|
||||||
|
permissions:
|
||||||
|
pull-requests: write # for codelytv/pr-size-labeler to add labels & comment on PRs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Label the PR size
|
||||||
|
steps:
|
||||||
|
- uses: codelytv/pr-size-labeler@v1.8.1
|
||||||
|
with:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
xs_label: 'size/XS'
|
||||||
|
xs_max_size: '10'
|
||||||
|
s_label: 'size/S'
|
||||||
|
s_max_size: '24'
|
||||||
|
m_label: 'size/M'
|
||||||
|
m_max_size: '99'
|
||||||
|
l_label: 'size/L'
|
||||||
|
l_max_size: '200'
|
||||||
|
xl_label: 'size/XL'
|
||||||
|
fail_if_xl: 'false'
|
||||||
|
message_if_xl: >
|
||||||
|
'This PR exceeds the recommended size of 200 lines.
|
||||||
|
Please make sure you are NOT addressing multiple issues with one PR.
|
||||||
|
Note this PR might be rejected due to its size.’
|
49
.github/workflows/stale.yml
vendored
49
.github/workflows/stale.yml
vendored
|
@ -4,18 +4,53 @@ on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "0 0 * * *"
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
issues: write # for actions/stale to close stale issues
|
||||||
|
pull-requests: write # for actions/stale to close stale PRs
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v1
|
- uses: actions/stale@v6
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'This issue is being marked as stale due to a long period of inactivity'
|
stale-issue-message: "The Cobra project currently lacks enough contributors to adequately respond to all issues.
|
||||||
stale-pr-message: 'This PR is being marked as stale due to a long period of inactivity'
|
This bot triages issues and PRs according to the following rules:
|
||||||
stale-issue-label: 'kind/stale'
|
|
||||||
stale-pr-label: 'kind/stale'
|
- After 60d of inactivity, lifecycle/stale is applied.
|
||||||
exempt-issue-label: 'kind/stale'
|
- After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the issue is closed.
|
||||||
exempt-pr-label: 'kind/stale'
|
|
||||||
|
You can:
|
||||||
|
|
||||||
|
- Make a comment to remove the stale label and show your support. The 60 days reset.
|
||||||
|
- If an issue has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interseted in reopening"
|
||||||
|
|
||||||
|
stale-pr-message: "The Cobra project currently lacks enough contributors to adequately respond to all PRs.
|
||||||
|
This bot triages issues and PRs according to the following rules:
|
||||||
|
|
||||||
|
- After 60d of inactivity, lifecycle/stale is applied.
|
||||||
|
- After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied and the PR is closed.
|
||||||
|
|
||||||
|
You can:
|
||||||
|
|
||||||
|
- Make a comment to remove the stale label and show your support. The 60 days reset.
|
||||||
|
- If a PR has lifecycle/rotten and is closed, comment and ask maintainers if they'd be interseted in reopening."
|
||||||
|
|
||||||
|
days-before-stale: 60
|
||||||
|
days-before-close: 30
|
||||||
|
stale-issue-label: 'lifecycle/stale'
|
||||||
|
stale-pr-label: 'lifecycle/stale'
|
||||||
|
exempt-issue-labels: 'lifecycle/frozen'
|
||||||
|
exempt-pr-labels: 'lifecycle/frozen'
|
||||||
|
close-issue-label: 'lifecycle/rotten'
|
||||||
|
close-pr-label: 'lifecycle/rotten'
|
||||||
|
|
||||||
|
# Since cobra has so many legacy issues and PRs that need to be triaged,
|
||||||
|
# only label new PRs and issues.
|
||||||
|
start-date: '2022-02-01T00:00:00Z'
|
||||||
|
|
||||||
|
|
128
.github/workflows/test.yml
vendored
Normal file
128
.github/workflows/test.yml
vendored
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
name: Test
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
env:
|
||||||
|
GO111MODULE: on
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
|
||||||
|
lic-headers:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- run: >-
|
||||||
|
docker run
|
||||||
|
-v $(pwd):/wrk -w /wrk
|
||||||
|
ghcr.io/google/addlicense
|
||||||
|
-c 'The Cobra Authors'
|
||||||
|
-y '2013-2022'
|
||||||
|
-l apache
|
||||||
|
-ignore '.github/**'
|
||||||
|
-check
|
||||||
|
.
|
||||||
|
|
||||||
|
|
||||||
|
golangci-lint:
|
||||||
|
permissions:
|
||||||
|
contents: read # for actions/checkout to fetch code
|
||||||
|
pull-requests: read # for golangci/golangci-lint-action to fetch pull requests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: '^1.19'
|
||||||
|
check-latest: true
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: golangci/golangci-lint-action@v3.2.0
|
||||||
|
with:
|
||||||
|
version: latest
|
||||||
|
args: --verbose
|
||||||
|
|
||||||
|
|
||||||
|
test-unix:
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform:
|
||||||
|
- ubuntu
|
||||||
|
- macOS
|
||||||
|
go:
|
||||||
|
- 15
|
||||||
|
- 16
|
||||||
|
- 17
|
||||||
|
- 18
|
||||||
|
- 19
|
||||||
|
name: '${{ matrix.platform }} | 1.${{ matrix.go }}.x'
|
||||||
|
runs-on: ${{ matrix.platform }}-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/setup-go@v3
|
||||||
|
with:
|
||||||
|
go-version: 1.${{ matrix.go }}.x
|
||||||
|
cache: true
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
export GOBIN=$HOME/go/bin
|
||||||
|
case "${{ matrix.go }}" in
|
||||||
|
14|15) _version='';;
|
||||||
|
*) _version='@latest';;
|
||||||
|
esac
|
||||||
|
go install github.com/kyoh86/richgo"${_version}"
|
||||||
|
go install github.com/mitchellh/gox"${_version}"
|
||||||
|
|
||||||
|
- run: RICHGO_FORCE_COLOR=1 PATH=$HOME/go/bin/:$PATH make test
|
||||||
|
|
||||||
|
|
||||||
|
test-win:
|
||||||
|
name: MINGW64
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: msys2 {0}
|
||||||
|
runs-on: windows-latest
|
||||||
|
steps:
|
||||||
|
|
||||||
|
- shell: bash
|
||||||
|
run: git config --global core.autocrlf input
|
||||||
|
|
||||||
|
- uses: msys2/setup-msys2@v2
|
||||||
|
with:
|
||||||
|
msystem: MINGW64
|
||||||
|
update: true
|
||||||
|
install: >
|
||||||
|
git
|
||||||
|
make
|
||||||
|
unzip
|
||||||
|
mingw-w64-x86_64-go
|
||||||
|
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/go/pkg/mod
|
||||||
|
key: ${{ runner.os }}-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
|
||||||
|
restore-keys: ${{ runner.os }}-${{ matrix.go }}-
|
||||||
|
|
||||||
|
- run: |
|
||||||
|
export GOBIN=$HOME/go/bin
|
||||||
|
go install github.com/kyoh86/richgo@latest
|
||||||
|
go install github.com/mitchellh/gox@latest
|
||||||
|
|
||||||
|
- run: RICHGO_FORCE_COLOR=1 PATH=$HOME/go/bin:$PATH make test
|
|
@ -1,3 +1,17 @@
|
||||||
|
# Copyright 2013-2022 The Cobra Authors
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
|
||||||
run:
|
run:
|
||||||
deadline: 5m
|
deadline: 5m
|
||||||
|
|
||||||
|
|
51
CHANGELOG.md
51
CHANGELOG.md
|
@ -1,51 +0,0 @@
|
||||||
# Cobra Changelog
|
|
||||||
|
|
||||||
## v1.1.3
|
|
||||||
|
|
||||||
* **Fix:** release-branch.cobra1.1 only: Revert "Deprecate Go < 1.14" to maintain backward compatibility
|
|
||||||
|
|
||||||
## v1.1.2
|
|
||||||
|
|
||||||
### Notable Changes
|
|
||||||
|
|
||||||
* Bump license year to 2021 in golden files (#1309) @Bowbaq
|
|
||||||
* Enhance PowerShell completion with custom comp (#1208) @Luap99
|
|
||||||
* Update gopkg.in/yaml.v2 to v2.4.0: The previous breaking change in yaml.v2 v2.3.0 has been reverted, see go-yaml/yaml#670
|
|
||||||
* Documentation readability improvements (#1228 etc.) @zaataylor etc.
|
|
||||||
* Use golangci-lint: Repair warnings and errors resulting from linting (#1044) @umarcor
|
|
||||||
|
|
||||||
## v1.1.1
|
|
||||||
|
|
||||||
* **Fix:** yaml.v2 2.3.0 contained a unintended breaking change. This release reverts to yaml.v2 v2.2.8 which has recent critical CVE fixes, but does not have the breaking changes. See https://github.com/spf13/cobra/pull/1259 for context.
|
|
||||||
* **Fix:** correct internal formatting for go-md2man v2 (which caused man page generation to be broken). See https://github.com/spf13/cobra/issues/1049 for context.
|
|
||||||
|
|
||||||
## v1.1.0
|
|
||||||
|
|
||||||
### Notable Changes
|
|
||||||
|
|
||||||
* Extend Go completions and revamp zsh comp (#1070)
|
|
||||||
* Fix man page doc generation - no auto generated tag when `cmd.DisableAutoGenTag = true` (#1104) @jpmcb
|
|
||||||
* Add completion for help command (#1136)
|
|
||||||
* Complete subcommands when TraverseChildren is set (#1171)
|
|
||||||
* Fix stderr printing functions (#894)
|
|
||||||
* fix: fish output redirection (#1247)
|
|
||||||
|
|
||||||
## v1.0.0
|
|
||||||
|
|
||||||
Announcing v1.0.0 of Cobra. 🎉
|
|
||||||
|
|
||||||
### Notable Changes
|
|
||||||
* Fish completion (including support for Go custom completion) @marckhouzam
|
|
||||||
* API (urgent): Rename BashCompDirectives to ShellCompDirectives @marckhouzam
|
|
||||||
* Remove/replace SetOutput on Command - deprecated @jpmcb
|
|
||||||
* add support for autolabel stale PR @xchapter7x
|
|
||||||
* Add Labeler Actions @xchapter7x
|
|
||||||
* Custom completions coded in Go (instead of Bash) @marckhouzam
|
|
||||||
* Partial Revert of #922 @jharshman
|
|
||||||
* Add Makefile to project @jharshman
|
|
||||||
* Correct documentation for InOrStdin @desponda
|
|
||||||
* Apply formatting to templates @jharshman
|
|
||||||
* Revert change so help is printed on stdout again @marckhouzam
|
|
||||||
* Update md2man to v2.0.0 @pdf
|
|
||||||
* update viper to v1.4.0 @umarcor
|
|
||||||
* Update cmd/root.go example in README.md @jharshman
|
|
13
MAINTAINERS
Normal file
13
MAINTAINERS
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
maintainers:
|
||||||
|
- spf13
|
||||||
|
- johnSchnake
|
||||||
|
- jpmcb
|
||||||
|
- marckhouzam
|
||||||
|
inactive:
|
||||||
|
- anthonyfok
|
||||||
|
- bep
|
||||||
|
- bogem
|
||||||
|
- broady
|
||||||
|
- eparis
|
||||||
|
- jharshman
|
||||||
|
- wfernandes
|
13
Makefile
13
Makefile
|
@ -6,14 +6,14 @@ $(warning "could not find golangci-lint in $(PATH), run: curl -sfL https://insta
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq (, $(shell which richgo))
|
ifeq (, $(shell which richgo))
|
||||||
$(warning "could not find richgo in $(PATH), run: go get github.com/kyoh86/richgo")
|
$(warning "could not find richgo in $(PATH), run: go install github.com/kyoh86/richgo@latest")
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: fmt lint test cobra_generator install_deps clean
|
.PHONY: fmt lint test install_deps clean
|
||||||
|
|
||||||
default: all
|
default: all
|
||||||
|
|
||||||
all: fmt test cobra_generator
|
all: fmt test
|
||||||
|
|
||||||
fmt:
|
fmt:
|
||||||
$(info ******************** checking formatting ********************)
|
$(info ******************** checking formatting ********************)
|
||||||
|
@ -23,15 +23,10 @@ lint:
|
||||||
$(info ******************** running lint tools ********************)
|
$(info ******************** running lint tools ********************)
|
||||||
golangci-lint run -v
|
golangci-lint run -v
|
||||||
|
|
||||||
test: install_deps lint
|
test: install_deps
|
||||||
$(info ******************** running tests ********************)
|
$(info ******************** running tests ********************)
|
||||||
richgo test -v ./...
|
richgo test -v ./...
|
||||||
|
|
||||||
cobra_generator: install_deps
|
|
||||||
$(info ******************** building generator ********************)
|
|
||||||
mkdir -p $(BIN)
|
|
||||||
make -C cobra all
|
|
||||||
|
|
||||||
install_deps:
|
install_deps:
|
||||||
$(info ******************** downloading dependencies ********************)
|
$(info ******************** downloading dependencies ********************)
|
||||||
go get -v ./...
|
go get -v ./...
|
||||||
|
|
62
README.md
62
README.md
|
@ -1,52 +1,26 @@
|
||||||

|

|
||||||
|
|
||||||
Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.
|
Cobra is a library for creating powerful modern CLI applications.
|
||||||
|
|
||||||
Cobra is used in many Go projects such as [Kubernetes](http://kubernetes.io/),
|
Cobra is used in many Go projects such as [Kubernetes](https://kubernetes.io/),
|
||||||
[Hugo](https://gohugo.io), and [Github CLI](https://github.com/cli/cli) to
|
[Hugo](https://gohugo.io), and [GitHub CLI](https://github.com/cli/cli) to
|
||||||
name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra.
|
name a few. [This list](./projects_using_cobra.md) contains a more extensive list of projects using Cobra.
|
||||||
|
|
||||||
[](https://github.com/spf13/cobra/actions?query=workflow%3ATest)
|
[](https://github.com/spf13/cobra/actions?query=workflow%3ATest)
|
||||||
[](https://godoc.org/github.com/spf13/cobra)
|
[](https://pkg.go.dev/github.com/spf13/cobra)
|
||||||
[](https://goreportcard.com/report/github.com/spf13/cobra)
|
[](https://goreportcard.com/report/github.com/spf13/cobra)
|
||||||
[](https://gophers.slack.com/archives/CD3LP1199)
|
[](https://gophers.slack.com/archives/CD3LP1199)
|
||||||
|
|
||||||
# Table of Contents
|
|
||||||
|
|
||||||
- [Overview](#overview)
|
|
||||||
- [Concepts](#concepts)
|
|
||||||
* [Commands](#commands)
|
|
||||||
* [Flags](#flags)
|
|
||||||
- [Installing](#installing)
|
|
||||||
- [Usage](#usage)
|
|
||||||
* [Using the Cobra Generator](user_guide.md#using-the-cobra-generator)
|
|
||||||
* [Using the Cobra Library](user_guide.md#using-the-cobra-library)
|
|
||||||
* [Working with Flags](user_guide.md#working-with-flags)
|
|
||||||
* [Positional and Custom Arguments](user_guide.md#positional-and-custom-arguments)
|
|
||||||
* [Example](user_guide.md#example)
|
|
||||||
* [Help Command](user_guide.md#help-command)
|
|
||||||
* [Usage Message](user_guide.md#usage-message)
|
|
||||||
* [PreRun and PostRun Hooks](user_guide.md#prerun-and-postrun-hooks)
|
|
||||||
* [Suggestions when "unknown command" happens](user_guide.md#suggestions-when-unknown-command-happens)
|
|
||||||
* [Generating documentation for your command](user_guide.md#generating-documentation-for-your-command)
|
|
||||||
* [Generating shell completions](user_guide.md#generating-shell-completions)
|
|
||||||
- [Contributing](CONTRIBUTING.md)
|
|
||||||
- [License](#license)
|
|
||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
Cobra is a library providing a simple interface to create powerful modern CLI
|
Cobra is a library providing a simple interface to create powerful modern CLI
|
||||||
interfaces similar to git & go tools.
|
interfaces similar to git & go tools.
|
||||||
|
|
||||||
Cobra is also an application that will generate your application scaffolding to rapidly
|
|
||||||
develop a Cobra-based application.
|
|
||||||
|
|
||||||
Cobra provides:
|
Cobra provides:
|
||||||
* Easy subcommand-based CLIs: `app server`, `app fetch`, etc.
|
* Easy subcommand-based CLIs: `app server`, `app fetch`, etc.
|
||||||
* Fully POSIX-compliant flags (including short & long versions)
|
* Fully POSIX-compliant flags (including short & long versions)
|
||||||
* Nested subcommands
|
* Nested subcommands
|
||||||
* Global, local and cascading flags
|
* Global, local and cascading flags
|
||||||
* Easy generation of applications & commands with `cobra init appname` & `cobra add cmdname`
|
|
||||||
* Intelligent suggestions (`app srver`... did you mean `app server`?)
|
* Intelligent suggestions (`app srver`... did you mean `app server`?)
|
||||||
* Automatic help generation for commands and flags
|
* Automatic help generation for commands and flags
|
||||||
* Automatic help flag recognition of `-h`, `--help`, etc.
|
* Automatic help flag recognition of `-h`, `--help`, etc.
|
||||||
|
@ -54,7 +28,7 @@ Cobra provides:
|
||||||
* Automatically generated man pages for your application
|
* Automatically generated man pages for your application
|
||||||
* Command aliases so you can change things without breaking them
|
* Command aliases so you can change things without breaking them
|
||||||
* The flexibility to define your own help, usage, etc.
|
* The flexibility to define your own help, usage, etc.
|
||||||
* Optional tight integration with [viper](http://github.com/spf13/viper) for 12-factor apps
|
* Optional seamless integration with [viper](https://github.com/spf13/viper) for 12-factor apps
|
||||||
|
|
||||||
# Concepts
|
# Concepts
|
||||||
|
|
||||||
|
@ -66,9 +40,9 @@ The best applications read like sentences when used, and as a result, users
|
||||||
intuitively know how to interact with them.
|
intuitively know how to interact with them.
|
||||||
|
|
||||||
The pattern to follow is
|
The pattern to follow is
|
||||||
`APPNAME VERB NOUN --ADJECTIVE.`
|
`APPNAME VERB NOUN --ADJECTIVE`
|
||||||
or
|
or
|
||||||
`APPNAME COMMAND ARG --FLAG`
|
`APPNAME COMMAND ARG --FLAG`.
|
||||||
|
|
||||||
A few good real world examples may better illustrate this point.
|
A few good real world examples may better illustrate this point.
|
||||||
|
|
||||||
|
@ -88,7 +62,7 @@ have children commands and optionally run an action.
|
||||||
|
|
||||||
In the example above, 'server' is the command.
|
In the example above, 'server' is the command.
|
||||||
|
|
||||||
[More about cobra.Command](https://godoc.org/github.com/spf13/cobra#Command)
|
[More about cobra.Command](https://pkg.go.dev/github.com/spf13/cobra#Command)
|
||||||
|
|
||||||
## Flags
|
## Flags
|
||||||
|
|
||||||
|
@ -105,10 +79,11 @@ which maintains the same interface while adding POSIX compliance.
|
||||||
|
|
||||||
# Installing
|
# Installing
|
||||||
Using Cobra is easy. First, use `go get` to install the latest version
|
Using Cobra is easy. First, use `go get` to install the latest version
|
||||||
of the library. This command will install the `cobra` generator executable
|
of the library.
|
||||||
along with the library and its dependencies:
|
|
||||||
|
|
||||||
go get -u github.com/spf13/cobra
|
```
|
||||||
|
go get -u github.com/spf13/cobra@latest
|
||||||
|
```
|
||||||
|
|
||||||
Next, include Cobra in your application:
|
Next, include Cobra in your application:
|
||||||
|
|
||||||
|
@ -117,8 +92,19 @@ import "github.com/spf13/cobra"
|
||||||
```
|
```
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
|
`cobra-cli` is a command line program to generate cobra applications and command files.
|
||||||
|
It will bootstrap your application scaffolding to rapidly
|
||||||
|
develop a Cobra-based application. It is the easiest way to incorporate Cobra into your application.
|
||||||
|
|
||||||
See [User Guide](user_guide.md).
|
It can be installed by running:
|
||||||
|
|
||||||
|
```
|
||||||
|
go install github.com/spf13/cobra-cli@latest
|
||||||
|
```
|
||||||
|
|
||||||
|
For complete details on using the Cobra-CLI generator, please read [The Cobra Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)
|
||||||
|
|
||||||
|
For complete details on using the Cobra library, please read the [The Cobra User Guide](user_guide.md).
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
||||||
|
|
63
active_help.go
Normal file
63
active_help.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
activeHelpMarker = "_activeHelp_ "
|
||||||
|
// The below values should not be changed: programs will be using them explicitly
|
||||||
|
// in their user documentation, and users will be using them explicitly.
|
||||||
|
activeHelpEnvVarSuffix = "_ACTIVE_HELP"
|
||||||
|
activeHelpGlobalEnvVar = "COBRA_ACTIVE_HELP"
|
||||||
|
activeHelpGlobalDisable = "0"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppendActiveHelp adds the specified string to the specified array to be used as ActiveHelp.
|
||||||
|
// Such strings will be processed by the completion script and will be shown as ActiveHelp
|
||||||
|
// to the user.
|
||||||
|
// The array parameter should be the array that will contain the completions.
|
||||||
|
// This function can be called multiple times before and/or after completions are added to
|
||||||
|
// the array. Each time this function is called with the same array, the new
|
||||||
|
// ActiveHelp line will be shown below the previous ones when completion is triggered.
|
||||||
|
func AppendActiveHelp(compArray []string, activeHelpStr string) []string {
|
||||||
|
return append(compArray, fmt.Sprintf("%s%s", activeHelpMarker, activeHelpStr))
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetActiveHelpConfig returns the value of the ActiveHelp environment variable
|
||||||
|
// <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the root command in upper
|
||||||
|
// case, with all - replaced by _.
|
||||||
|
// It will always return "0" if the global environment variable COBRA_ACTIVE_HELP
|
||||||
|
// is set to "0".
|
||||||
|
func GetActiveHelpConfig(cmd *Command) string {
|
||||||
|
activeHelpCfg := os.Getenv(activeHelpGlobalEnvVar)
|
||||||
|
if activeHelpCfg != activeHelpGlobalDisable {
|
||||||
|
activeHelpCfg = os.Getenv(activeHelpEnvVar(cmd.Root().Name()))
|
||||||
|
}
|
||||||
|
return activeHelpCfg
|
||||||
|
}
|
||||||
|
|
||||||
|
// activeHelpEnvVar returns the name of the program-specific ActiveHelp environment
|
||||||
|
// variable. It has the format <PROGRAM>_ACTIVE_HELP where <PROGRAM> is the name of the
|
||||||
|
// root command in upper case, with all - replaced by _.
|
||||||
|
func activeHelpEnvVar(name string) string {
|
||||||
|
// This format should not be changed: users will be using it explicitly.
|
||||||
|
activeHelpEnvVar := strings.ToUpper(fmt.Sprintf("%s%s", name, activeHelpEnvVarSuffix))
|
||||||
|
return strings.ReplaceAll(activeHelpEnvVar, "-", "_")
|
||||||
|
}
|
157
active_help.md
Normal file
157
active_help.md
Normal file
|
@ -0,0 +1,157 @@
|
||||||
|
# Active Help
|
||||||
|
|
||||||
|
Active Help is a framework provided by Cobra which allows a program to define messages (hints, warnings, etc) that will be printed during program usage. It aims to make it easier for your users to learn how to use your program. If configured by the program, Active Help is printed when the user triggers shell completion.
|
||||||
|
|
||||||
|
For example,
|
||||||
|
```
|
||||||
|
bash-5.1$ helm repo add [tab]
|
||||||
|
You must choose a name for the repo you are adding.
|
||||||
|
|
||||||
|
bash-5.1$ bin/helm package [tab]
|
||||||
|
Please specify the path to the chart to package
|
||||||
|
|
||||||
|
bash-5.1$ bin/helm package [tab][tab]
|
||||||
|
bin/ internal/ scripts/ pkg/ testdata/
|
||||||
|
```
|
||||||
|
|
||||||
|
**Hint**: A good place to use Active Help messages is when the normal completion system does not provide any suggestions. In such cases, Active Help nicely supplements the normal shell completions to guide the user in knowing what is expected by the program.
|
||||||
|
## Supported shells
|
||||||
|
|
||||||
|
Active Help is currently only supported for the following shells:
|
||||||
|
- Bash (using [bash completion V2](shell_completions.md#bash-completion-v2) only). Note that bash 4.4 or higher is required for the prompt to appear when an Active Help message is printed.
|
||||||
|
- Zsh
|
||||||
|
|
||||||
|
## Adding Active Help messages
|
||||||
|
|
||||||
|
As Active Help uses the shell completion system, the implementation of Active Help messages is done by enhancing custom dynamic completions. If you are not familiar with dynamic completions, please refer to [Shell Completions](shell_completions.md).
|
||||||
|
|
||||||
|
Adding Active Help is done through the use of the `cobra.AppendActiveHelp(...)` function, where the program repeatedly adds Active Help messages to the list of completions. Keep reading for details.
|
||||||
|
|
||||||
|
### Active Help for nouns
|
||||||
|
|
||||||
|
Adding Active Help when completing a noun is done within the `ValidArgsFunction(...)` of a command. Please notice the use of `cobra.AppendActiveHelp(...)` in the following example:
|
||||||
|
|
||||||
|
```go
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "add [NAME] [URL]",
|
||||||
|
Short: "add a chart repository",
|
||||||
|
Args: require.ExactArgs(2),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
return addRepo(args)
|
||||||
|
},
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
var comps []string
|
||||||
|
if len(args) == 0 {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "You must choose a name for the repo you are adding")
|
||||||
|
} else if len(args) == 1 {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "You must specify the URL for the repo you are adding")
|
||||||
|
} else {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "This command does not take any more arguments")
|
||||||
|
}
|
||||||
|
return comps, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
The example above defines the completions (none, in this specific example) as well as the Active Help messages for the `helm repo add` command. It yields the following behavior:
|
||||||
|
```
|
||||||
|
bash-5.1$ helm repo add [tab]
|
||||||
|
You must choose a name for the repo you are adding
|
||||||
|
|
||||||
|
bash-5.1$ helm repo add grafana [tab]
|
||||||
|
You must specify the URL for the repo you are adding
|
||||||
|
|
||||||
|
bash-5.1$ helm repo add grafana https://grafana.github.io/helm-charts [tab]
|
||||||
|
This command does not take any more arguments
|
||||||
|
```
|
||||||
|
**Hint**: As can be seen in the above example, a good place to use Active Help messages is when the normal completion system does not provide any suggestions. In such cases, Active Help nicely supplements the normal shell completions.
|
||||||
|
|
||||||
|
### Active Help for flags
|
||||||
|
|
||||||
|
Providing Active Help for flags is done in the same fashion as for nouns, but using the completion function registered for the flag. For example:
|
||||||
|
```go
|
||||||
|
_ = cmd.RegisterFlagCompletionFunc("version", func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
if len(args) != 2 {
|
||||||
|
return cobra.AppendActiveHelp(nil, "You must first specify the chart to install before the --version flag can be completed"), cobra.ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
return compVersionFlag(args[1], toComplete)
|
||||||
|
})
|
||||||
|
```
|
||||||
|
The example above prints an Active Help message when not enough information was given by the user to complete the `--version` flag.
|
||||||
|
```
|
||||||
|
bash-5.1$ bin/helm install myrelease --version 2.0.[tab]
|
||||||
|
You must first specify the chart to install before the --version flag can be completed
|
||||||
|
|
||||||
|
bash-5.1$ bin/helm install myrelease bitnami/solr --version 2.0.[tab][tab]
|
||||||
|
2.0.1 2.0.2 2.0.3
|
||||||
|
```
|
||||||
|
|
||||||
|
## User control of Active Help
|
||||||
|
|
||||||
|
You may want to allow your users to disable Active Help or choose between different levels of Active Help. It is entirely up to the program to define the type of configurability of Active Help that it wants to offer, if any.
|
||||||
|
Allowing to configure Active Help is entirely optional; you can use Active Help in your program without doing anything about Active Help configuration.
|
||||||
|
|
||||||
|
The way to configure Active Help is to use the program's Active Help environment
|
||||||
|
variable. That variable is named `<PROGRAM>_ACTIVE_HELP` where `<PROGRAM>` is the name of your
|
||||||
|
program in uppercase with any `-` replaced by an `_`. The variable should be set by the user to whatever
|
||||||
|
Active Help configuration values are supported by the program.
|
||||||
|
|
||||||
|
For example, say `helm` has chosen to support three levels for Active Help: `on`, `off`, `local`. Then a user
|
||||||
|
would set the desired behavior to `local` by doing `export HELM_ACTIVE_HELP=local` in their shell.
|
||||||
|
|
||||||
|
For simplicity, when in `cmd.ValidArgsFunction(...)` or a flag's completion function, the program should read the
|
||||||
|
Active Help configuration using the `cobra.GetActiveHelpConfig(cmd)` function and select what Active Help messages
|
||||||
|
should or should not be added (instead of reading the environment variable directly).
|
||||||
|
|
||||||
|
For example:
|
||||||
|
```go
|
||||||
|
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
|
||||||
|
activeHelpLevel := cobra.GetActiveHelpConfig(cmd)
|
||||||
|
|
||||||
|
var comps []string
|
||||||
|
if len(args) == 0 {
|
||||||
|
if activeHelpLevel != "off" {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "You must choose a name for the repo you are adding")
|
||||||
|
}
|
||||||
|
} else if len(args) == 1 {
|
||||||
|
if activeHelpLevel != "off" {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "You must specify the URL for the repo you are adding")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if activeHelpLevel == "local" {
|
||||||
|
comps = cobra.AppendActiveHelp(comps, "This command does not take any more arguments")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return comps, cobra.ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
```
|
||||||
|
**Note 1**: If the `<PROGRAM>_ACTIVE_HELP` environment variable is set to the string "0", Cobra will automatically disable all Active Help output (even if some output was specified by the program using the `cobra.AppendActiveHelp(...)` function). Using "0" can simplify your code in situations where you want to blindly disable Active Help without having to call `cobra.GetActiveHelpConfig(cmd)` explicitly.
|
||||||
|
|
||||||
|
**Note 2**: If a user wants to disable Active Help for every single program based on Cobra, she can set the environment variable `COBRA_ACTIVE_HELP` to "0". In this case `cobra.GetActiveHelpConfig(cmd)` will return "0" no matter what the variable `<PROGRAM>_ACTIVE_HELP` is set to.
|
||||||
|
|
||||||
|
**Note 3**: If the user does not set `<PROGRAM>_ACTIVE_HELP` or `COBRA_ACTIVE_HELP` (which will be a common case), the default value for the Active Help configuration returned by `cobra.GetActiveHelpConfig(cmd)` will be the empty string.
|
||||||
|
## Active Help with Cobra's default completion command
|
||||||
|
|
||||||
|
Cobra provides a default `completion` command for programs that wish to use it.
|
||||||
|
When using the default `completion` command, Active Help is configurable in the same
|
||||||
|
fashion as described above using environment variables. You may wish to document this in more
|
||||||
|
details for your users.
|
||||||
|
|
||||||
|
## Debugging Active Help
|
||||||
|
|
||||||
|
Debugging your Active Help code is done in the same way as debugging your dynamic completion code, which is with Cobra's hidden `__complete` command. Please refer to [debugging shell completion](shell_completions.md#debugging) for details.
|
||||||
|
|
||||||
|
When debugging with the `__complete` command, if you want to specify different Active Help configurations, you should use the active help environment variable. That variable is named `<PROGRAM>_ACTIVE_HELP` where any `-` is replaced by an `_`. For example, we can test deactivating some Active Help as shown below:
|
||||||
|
```
|
||||||
|
$ HELM_ACTIVE_HELP=1 bin/helm __complete install wordpress bitnami/h<ENTER>
|
||||||
|
bitnami/haproxy
|
||||||
|
bitnami/harbor
|
||||||
|
_activeHelp_ WARNING: cannot re-use a name that is still in use
|
||||||
|
:0
|
||||||
|
Completion ended with directive: ShellCompDirectiveDefault
|
||||||
|
|
||||||
|
$ HELM_ACTIVE_HELP=0 bin/helm __complete install wordpress bitnami/h<ENTER>
|
||||||
|
bitnami/haproxy
|
||||||
|
bitnami/harbor
|
||||||
|
:0
|
||||||
|
Completion ended with directive: ShellCompDirectiveDefault
|
||||||
|
```
|
400
active_help_test.go
Normal file
400
active_help_test.go
Normal file
|
@ -0,0 +1,400 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
activeHelpMessage = "This is an activeHelp message"
|
||||||
|
activeHelpMessage2 = "This is the rest of the activeHelp message"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestActiveHelpAlone(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
activeHelpFunc := func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := AppendActiveHelp(nil, activeHelpMessage)
|
||||||
|
return comps, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that activeHelp can be added to a root command
|
||||||
|
rootCmd.ValidArgsFunction = activeHelpFunc
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd.ValidArgsFunction = nil
|
||||||
|
|
||||||
|
// Test that activeHelp can be added to a child command
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "thechild",
|
||||||
|
Short: "The child command",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
childCmd.ValidArgsFunction = activeHelpFunc
|
||||||
|
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestActiveHelpWithComps(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "thechild",
|
||||||
|
Short: "The child command",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
// Test that activeHelp can be added following other completions
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := []string{"first", "second"}
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
return comps, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
"second",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that activeHelp can be added preceding other completions
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
var comps []string
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
comps = append(comps, []string{"first", "second"}...)
|
||||||
|
return comps, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
"first",
|
||||||
|
"second",
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that activeHelp can be added interleaved with other completions
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := []string{"first"}
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
comps = append(comps, "second")
|
||||||
|
return comps, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
"second",
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMultiActiveHelp(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "thechild",
|
||||||
|
Short: "The child command",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
// Test that multiple activeHelp message can be added
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := AppendActiveHelp(nil, activeHelpMessage)
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage2)
|
||||||
|
return comps, ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage2),
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that multiple activeHelp messages can be used along with completions
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := []string{"first"}
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
comps = append(comps, "second")
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage2)
|
||||||
|
return comps, ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
"second",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage2),
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestActiveHelpForFlag(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
flagname := "flag"
|
||||||
|
rootCmd.Flags().String(flagname, "", "A flag")
|
||||||
|
|
||||||
|
// Test that multiple activeHelp message can be added
|
||||||
|
_ = rootCmd.RegisterFlagCompletionFunc(flagname, func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := []string{"first"}
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
comps = append(comps, "second")
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage2)
|
||||||
|
return comps, ShellCompDirectiveNoFileComp
|
||||||
|
})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "--flag", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage),
|
||||||
|
"second",
|
||||||
|
fmt.Sprintf("%s%s", activeHelpMarker, activeHelpMessage2),
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestConfigActiveHelp(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "thechild",
|
||||||
|
Short: "The child command",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
activeHelpCfg := "someconfig,anotherconfig"
|
||||||
|
// Set the variable that the user would be setting
|
||||||
|
os.Setenv(activeHelpEnvVar(rootCmd.Name()), activeHelpCfg)
|
||||||
|
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
receivedActiveHelpCfg := GetActiveHelpConfig(cmd)
|
||||||
|
if receivedActiveHelpCfg != activeHelpCfg {
|
||||||
|
t.Errorf("expected activeHelpConfig: %q, but got: %q", activeHelpCfg, receivedActiveHelpCfg)
|
||||||
|
}
|
||||||
|
return nil, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test active help config for a flag
|
||||||
|
activeHelpCfg = "a config for a flag"
|
||||||
|
// Set the variable that the completions scripts will be setting
|
||||||
|
os.Setenv(activeHelpEnvVar(rootCmd.Name()), activeHelpCfg)
|
||||||
|
|
||||||
|
flagname := "flag"
|
||||||
|
childCmd.Flags().String(flagname, "", "A flag")
|
||||||
|
|
||||||
|
// Test that multiple activeHelp message can be added
|
||||||
|
_ = childCmd.RegisterFlagCompletionFunc(flagname, func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
receivedActiveHelpCfg := GetActiveHelpConfig(cmd)
|
||||||
|
if receivedActiveHelpCfg != activeHelpCfg {
|
||||||
|
t.Errorf("expected activeHelpConfig: %q, but got: %q", activeHelpCfg, receivedActiveHelpCfg)
|
||||||
|
}
|
||||||
|
return nil, ShellCompDirectiveDefault
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "--flag", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDisableActiveHelp(t *testing.T) {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "thechild",
|
||||||
|
Short: "The child command",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
// Test the disabling of activeHelp using the specific program
|
||||||
|
// environment variable that the completions scripts will be setting.
|
||||||
|
// Make sure the disabling value is "0" by hard-coding it in the tests;
|
||||||
|
// this is for backwards-compatibility as programs will be using this value.
|
||||||
|
os.Setenv(activeHelpEnvVar(rootCmd.Name()), "0")
|
||||||
|
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
comps := []string{"first"}
|
||||||
|
comps = AppendActiveHelp(comps, activeHelpMessage)
|
||||||
|
return comps, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
os.Unsetenv(activeHelpEnvVar(rootCmd.Name()))
|
||||||
|
|
||||||
|
// Make sure there is no ActiveHelp in the output
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Now test the global disabling of ActiveHelp
|
||||||
|
os.Setenv(activeHelpGlobalEnvVar, "0")
|
||||||
|
// Set the specific variable, to make sure it is ignored when the global env
|
||||||
|
// var is set properly
|
||||||
|
os.Setenv(activeHelpEnvVar(rootCmd.Name()), "1")
|
||||||
|
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure there is no ActiveHelp in the output
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
"first",
|
||||||
|
":0",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveDefault", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure that if the global env variable is set to anything else than
|
||||||
|
// the disable value it is ignored
|
||||||
|
os.Setenv(activeHelpGlobalEnvVar, "on")
|
||||||
|
// Set the specific variable, to make sure it is used (while ignoring the global env var)
|
||||||
|
activeHelpCfg := "1"
|
||||||
|
os.Setenv(activeHelpEnvVar(rootCmd.Name()), activeHelpCfg)
|
||||||
|
|
||||||
|
childCmd.ValidArgsFunction = func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
receivedActiveHelpCfg := GetActiveHelpConfig(cmd)
|
||||||
|
if receivedActiveHelpCfg != activeHelpCfg {
|
||||||
|
t.Errorf("expected activeHelpConfig: %q, but got: %q", activeHelpCfg, receivedActiveHelpCfg)
|
||||||
|
}
|
||||||
|
return nil, ShellCompDirectiveDefault
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "thechild", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
50
args.go
50
args.go
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -32,7 +46,8 @@ func NoArgs(cmd *Command, args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// OnlyValidArgs returns an error if any args are not in the list of ValidArgs.
|
// OnlyValidArgs returns an error if there are any positional args that are not in
|
||||||
|
// the `ValidArgs` field of `Command`
|
||||||
func OnlyValidArgs(cmd *Command, args []string) error {
|
func OnlyValidArgs(cmd *Command, args []string) error {
|
||||||
if len(cmd.ValidArgs) > 0 {
|
if len(cmd.ValidArgs) > 0 {
|
||||||
// Remove any description that may be included in ValidArgs.
|
// Remove any description that may be included in ValidArgs.
|
||||||
|
@ -41,7 +56,6 @@ func OnlyValidArgs(cmd *Command, args []string) error {
|
||||||
for _, v := range cmd.ValidArgs {
|
for _, v := range cmd.ValidArgs {
|
||||||
validArgs = append(validArgs, strings.Split(v, "\t")[0])
|
validArgs = append(validArgs, strings.Split(v, "\t")[0])
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range args {
|
for _, v := range args {
|
||||||
if !stringInSlice(v, validArgs) {
|
if !stringInSlice(v, validArgs) {
|
||||||
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
|
return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0]))
|
||||||
|
@ -86,18 +100,6 @@ func ExactArgs(n int) PositionalArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExactValidArgs returns an error if
|
|
||||||
// there are not exactly N positional args OR
|
|
||||||
// there are any positional args that are not in the `ValidArgs` field of `Command`
|
|
||||||
func ExactValidArgs(n int) PositionalArgs {
|
|
||||||
return func(cmd *Command, args []string) error {
|
|
||||||
if err := ExactArgs(n)(cmd, args); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return OnlyValidArgs(cmd, args)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RangeArgs returns an error if the number of args is not within the expected range.
|
// RangeArgs returns an error if the number of args is not within the expected range.
|
||||||
func RangeArgs(min int, max int) PositionalArgs {
|
func RangeArgs(min int, max int) PositionalArgs {
|
||||||
return func(cmd *Command, args []string) error {
|
return func(cmd *Command, args []string) error {
|
||||||
|
@ -107,3 +109,23 @@ func RangeArgs(min int, max int) PositionalArgs {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MatchAll allows combining several PositionalArgs to work in concert.
|
||||||
|
func MatchAll(pargs ...PositionalArgs) PositionalArgs {
|
||||||
|
return func(cmd *Command, args []string) error {
|
||||||
|
for _, parg := range pargs {
|
||||||
|
if err := parg(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExactValidArgs returns an error if there are not exactly N positional args OR
|
||||||
|
// there are any positional args that are not in the `ValidArgs` field of `Command`
|
||||||
|
//
|
||||||
|
// Deprecated: use MatchAll(ExactArgs(n), OnlyValidArgs) instead
|
||||||
|
func ExactValidArgs(n int) PositionalArgs {
|
||||||
|
return MatchAll(ExactArgs(n), OnlyValidArgs)
|
||||||
|
}
|
||||||
|
|
578
args_test.go
578
args_test.go
|
@ -1,46 +1,38 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNoArgs(t *testing.T) {
|
func getCommand(args PositionalArgs, withValid bool) *Command {
|
||||||
c := &Command{Use: "c", Args: NoArgs, Run: emptyRun}
|
|
||||||
|
|
||||||
output, err := executeCommand(c)
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected string: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestNoArgsWithArgs(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: NoArgs, Run: emptyRun}
|
|
||||||
|
|
||||||
_, err := executeCommand(c, "illegal")
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("Expected an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
got := err.Error()
|
|
||||||
expected := `unknown command "illegal" for "c"`
|
|
||||||
if got != expected {
|
|
||||||
t.Errorf("Expected: %q, got: %q", expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestOnlyValidArgs(t *testing.T) {
|
|
||||||
c := &Command{
|
c := &Command{
|
||||||
Use: "c",
|
Use: "c",
|
||||||
Args: OnlyValidArgs,
|
Args: args,
|
||||||
ValidArgs: []string{"one", "two"},
|
|
||||||
Run: emptyRun,
|
Run: emptyRun,
|
||||||
}
|
}
|
||||||
|
if withValid {
|
||||||
|
c.ValidArgs = []string{"one", "two", "three"}
|
||||||
|
}
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
output, err := executeCommand(c, "one", "two")
|
func expectSuccess(output string, err error, t *testing.T) {
|
||||||
if output != "" {
|
if output != "" {
|
||||||
t.Errorf("Unexpected output: %v", output)
|
t.Errorf("Unexpected output: %v", output)
|
||||||
}
|
}
|
||||||
|
@ -49,56 +41,32 @@ func TestOnlyValidArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOnlyValidArgsWithInvalidArgs(t *testing.T) {
|
func validOnlyWithInvalidArgs(err error, t *testing.T) {
|
||||||
c := &Command{
|
|
||||||
Use: "c",
|
|
||||||
Args: OnlyValidArgs,
|
|
||||||
ValidArgs: []string{"one", "two"},
|
|
||||||
Run: emptyRun,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := executeCommand(c, "three")
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected an error")
|
t.Fatal("Expected an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
got := err.Error()
|
got := err.Error()
|
||||||
expected := `invalid argument "three" for "c"`
|
expected := `invalid argument "a" for "c"`
|
||||||
if got != expected {
|
if got != expected {
|
||||||
t.Errorf("Expected: %q, got: %q", expected, got)
|
t.Errorf("Expected: %q, got: %q", expected, got)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestArbitraryArgs(t *testing.T) {
|
func noArgsWithArgs(err error, t *testing.T, arg string) {
|
||||||
c := &Command{Use: "c", Args: ArbitraryArgs, Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMinimumNArgs(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: MinimumNArgs(2), Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b", "c")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMinimumNArgsWithLessArgs(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: MinimumNArgs(2), Run: emptyRun}
|
|
||||||
_, err := executeCommand(c, "a")
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected an error")
|
t.Fatal("Expected an error")
|
||||||
}
|
}
|
||||||
|
got := err.Error()
|
||||||
|
expected := `unknown command "` + arg + `" for "c"`
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("Expected: %q, got: %q", expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func minimumNArgsWithLessArgs(err error, t *testing.T) {
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Expected an error")
|
||||||
|
}
|
||||||
got := err.Error()
|
got := err.Error()
|
||||||
expected := "requires at least 2 arg(s), only received 1"
|
expected := "requires at least 2 arg(s), only received 1"
|
||||||
if got != expected {
|
if got != expected {
|
||||||
|
@ -106,25 +74,10 @@ func TestMinimumNArgsWithLessArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMaximumNArgs(t *testing.T) {
|
func maximumNArgsWithMoreArgs(err error, t *testing.T) {
|
||||||
c := &Command{Use: "c", Args: MaximumNArgs(3), Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMaximumNArgsWithMoreArgs(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: MaximumNArgs(2), Run: emptyRun}
|
|
||||||
_, err := executeCommand(c, "a", "b", "c")
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected an error")
|
t.Fatal("Expected an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
got := err.Error()
|
got := err.Error()
|
||||||
expected := "accepts at most 2 arg(s), received 3"
|
expected := "accepts at most 2 arg(s), received 3"
|
||||||
if got != expected {
|
if got != expected {
|
||||||
|
@ -132,25 +85,10 @@ func TestMaximumNArgsWithMoreArgs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExactArgs(t *testing.T) {
|
func exactArgsWithInvalidCount(err error, t *testing.T) {
|
||||||
c := &Command{Use: "c", Args: ExactArgs(3), Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b", "c")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExactArgsWithInvalidCount(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: ExactArgs(2), Run: emptyRun}
|
|
||||||
_, err := executeCommand(c, "a", "b", "c")
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected an error")
|
t.Fatal("Expected an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
got := err.Error()
|
got := err.Error()
|
||||||
expected := "accepts 2 arg(s), received 3"
|
expected := "accepts 2 arg(s), received 3"
|
||||||
if got != expected {
|
if got != expected {
|
||||||
|
@ -158,71 +96,10 @@ func TestExactArgsWithInvalidCount(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExactValidArgs(t *testing.T) {
|
func rangeArgsWithInvalidCount(err error, t *testing.T) {
|
||||||
c := &Command{Use: "c", Args: ExactValidArgs(3), ValidArgs: []string{"a", "b", "c"}, Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b", "c")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExactValidArgsWithInvalidCount(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: ExactValidArgs(2), Run: emptyRun}
|
|
||||||
_, err := executeCommand(c, "a", "b", "c")
|
|
||||||
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("Expected an error")
|
t.Fatal("Expected an error")
|
||||||
}
|
}
|
||||||
|
|
||||||
got := err.Error()
|
|
||||||
expected := "accepts 2 arg(s), received 3"
|
|
||||||
if got != expected {
|
|
||||||
t.Fatalf("Expected %q, got %q", expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExactValidArgsWithInvalidArgs(t *testing.T) {
|
|
||||||
c := &Command{
|
|
||||||
Use: "c",
|
|
||||||
Args: ExactValidArgs(1),
|
|
||||||
ValidArgs: []string{"one", "two"},
|
|
||||||
Run: emptyRun,
|
|
||||||
}
|
|
||||||
|
|
||||||
_, err := executeCommand(c, "three")
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("Expected an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
got := err.Error()
|
|
||||||
expected := `invalid argument "three" for "c"`
|
|
||||||
if got != expected {
|
|
||||||
t.Errorf("Expected: %q, got: %q", expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRangeArgs(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: RangeArgs(2, 4), Run: emptyRun}
|
|
||||||
output, err := executeCommand(c, "a", "b", "c")
|
|
||||||
if output != "" {
|
|
||||||
t.Errorf("Unexpected output: %v", output)
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
t.Errorf("Unexpected error: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRangeArgsWithInvalidCount(t *testing.T) {
|
|
||||||
c := &Command{Use: "c", Args: RangeArgs(2, 4), Run: emptyRun}
|
|
||||||
_, err := executeCommand(c, "a")
|
|
||||||
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("Expected an error")
|
|
||||||
}
|
|
||||||
|
|
||||||
got := err.Error()
|
got := err.Error()
|
||||||
expected := "accepts between 2 and 4 arg(s), received 1"
|
expected := "accepts between 2 and 4 arg(s), received 1"
|
||||||
if got != expected {
|
if got != expected {
|
||||||
|
@ -230,6 +107,280 @@ func TestRangeArgsWithInvalidCount(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NoArgs
|
||||||
|
|
||||||
|
func TestNoArgs(t *testing.T) {
|
||||||
|
c := getCommand(NoArgs, false)
|
||||||
|
output, err := executeCommand(c)
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoArgs_WithArgs(t *testing.T) {
|
||||||
|
c := getCommand(NoArgs, false)
|
||||||
|
_, err := executeCommand(c, "one")
|
||||||
|
noArgsWithArgs(err, t, "one")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoArgs_WithValid_WithArgs(t *testing.T) {
|
||||||
|
c := getCommand(NoArgs, true)
|
||||||
|
_, err := executeCommand(c, "one")
|
||||||
|
noArgsWithArgs(err, t, "one")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(NoArgs, true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
noArgsWithArgs(err, t, "a")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, NoArgs), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// OnlyValidArgs
|
||||||
|
|
||||||
|
func TestOnlyValidArgs(t *testing.T) {
|
||||||
|
c := getCommand(OnlyValidArgs, true)
|
||||||
|
output, err := executeCommand(c, "one", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOnlyValidArgs_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(OnlyValidArgs, true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ArbitraryArgs
|
||||||
|
|
||||||
|
func TestArbitraryArgs(t *testing.T) {
|
||||||
|
c := getCommand(ArbitraryArgs, false)
|
||||||
|
output, err := executeCommand(c, "a", "b")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestArbitraryArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(ArbitraryArgs, true)
|
||||||
|
output, err := executeCommand(c, "one", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestArbitraryArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ArbitraryArgs, true)
|
||||||
|
output, err := executeCommand(c, "a")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestArbitraryArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, ArbitraryArgs), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MinimumNArgs
|
||||||
|
|
||||||
|
func TestMinimumNArgs(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), false)
|
||||||
|
output, err := executeCommand(c, "a", "b", "c")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), true)
|
||||||
|
output, err := executeCommand(c, "one", "three")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithValid__WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), true)
|
||||||
|
output, err := executeCommand(c, "a", "b")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true)
|
||||||
|
_, err := executeCommand(c, "a", "b")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithLessArgs(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), false)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
minimumNArgsWithLessArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithLessArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "one")
|
||||||
|
minimumNArgsWithLessArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithLessArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MinimumNArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
minimumNArgsWithLessArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMinimumNArgs_WithLessArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, MinimumNArgs(2)), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MaximumNArgs
|
||||||
|
|
||||||
|
func TestMaximumNArgs(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(3), false)
|
||||||
|
output, err := executeCommand(c, "a", "b")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(2), true)
|
||||||
|
output, err := executeCommand(c, "one", "three")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(2), true)
|
||||||
|
output, err := executeCommand(c, "a", "b")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true)
|
||||||
|
_, err := executeCommand(c, "a", "b")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithMoreArgs(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(2), false)
|
||||||
|
_, err := executeCommand(c, "a", "b", "c")
|
||||||
|
maximumNArgsWithMoreArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithMoreArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "one", "three", "two")
|
||||||
|
maximumNArgsWithMoreArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithMoreArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MaximumNArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "a", "b", "c")
|
||||||
|
maximumNArgsWithMoreArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMaximumNArgs_WithMoreArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, MaximumNArgs(2)), true)
|
||||||
|
_, err := executeCommand(c, "a", "b", "c")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExactArgs
|
||||||
|
|
||||||
|
func TestExactArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(3), false)
|
||||||
|
output, err := executeCommand(c, "a", "b", "c")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(3), true)
|
||||||
|
output, err := executeCommand(c, "three", "one", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(3), true)
|
||||||
|
output, err := executeCommand(c, "three", "a", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, ExactArgs(3)), true)
|
||||||
|
_, err := executeCommand(c, "three", "a", "two")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithInvalidCount(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(2), false)
|
||||||
|
_, err := executeCommand(c, "a", "b", "c")
|
||||||
|
exactArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithInvalidCount_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "three", "one", "two")
|
||||||
|
exactArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "three", "a", "two")
|
||||||
|
exactArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, ExactArgs(2)), true)
|
||||||
|
_, err := executeCommand(c, "three", "a", "two")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// RangeArgs
|
||||||
|
|
||||||
|
func TestRangeArgs(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), false)
|
||||||
|
output, err := executeCommand(c, "a", "b", "c")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), true)
|
||||||
|
output, err := executeCommand(c, "three", "one", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), true)
|
||||||
|
output, err := executeCommand(c, "three", "a", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true)
|
||||||
|
_, err := executeCommand(c, "three", "a", "two")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithInvalidCount(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), false)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
rangeArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithInvalidCount_WithValid(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), true)
|
||||||
|
_, err := executeCommand(c, "two")
|
||||||
|
rangeArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithInvalidCount_WithValid_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(RangeArgs(2, 4), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
rangeArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRangeArgs_WithInvalidCount_WithValidOnly_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(MatchAll(OnlyValidArgs, RangeArgs(2, 4)), true)
|
||||||
|
_, err := executeCommand(c, "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Takes(No)Args
|
||||||
|
|
||||||
func TestRootTakesNoArgs(t *testing.T) {
|
func TestRootTakesNoArgs(t *testing.T) {
|
||||||
rootCmd := &Command{Use: "root", Run: emptyRun}
|
rootCmd := &Command{Use: "root", Run: emptyRun}
|
||||||
childCmd := &Command{Use: "child", Run: emptyRun}
|
childCmd := &Command{Use: "child", Run: emptyRun}
|
||||||
|
@ -285,3 +436,106 @@ func TestChildTakesArgs(t *testing.T) {
|
||||||
t.Fatalf("Unexpected error: %v", err)
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatchAll(t *testing.T) {
|
||||||
|
// Somewhat contrived example check that ensures there are exactly 3
|
||||||
|
// arguments, and each argument is exactly 2 bytes long.
|
||||||
|
pargs := MatchAll(
|
||||||
|
ExactArgs(3),
|
||||||
|
func(cmd *Command, args []string) error {
|
||||||
|
for _, arg := range args {
|
||||||
|
if len([]byte(arg)) != 2 {
|
||||||
|
return fmt.Errorf("expected to be exactly 2 bytes long")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
args []string
|
||||||
|
fail bool
|
||||||
|
}{
|
||||||
|
"happy path": {
|
||||||
|
[]string{"aa", "bb", "cc"},
|
||||||
|
false,
|
||||||
|
},
|
||||||
|
"incorrect number of args": {
|
||||||
|
[]string{"aa", "bb", "cc", "dd"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
"incorrect number of bytes in one arg": {
|
||||||
|
[]string{"aa", "bb", "abc"},
|
||||||
|
true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd := &Command{Use: "root", Args: pargs, Run: emptyRun}
|
||||||
|
|
||||||
|
for name, tc := range testCases {
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
_, err := executeCommand(rootCmd, tc.args...)
|
||||||
|
if err != nil && !tc.fail {
|
||||||
|
t.Errorf("unexpected: %v\n", err)
|
||||||
|
}
|
||||||
|
if err == nil && tc.fail {
|
||||||
|
t.Errorf("expected error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DEPRECATED
|
||||||
|
|
||||||
|
func TestExactValidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactValidArgs(3), true)
|
||||||
|
output, err := executeCommand(c, "three", "one", "two")
|
||||||
|
expectSuccess(output, err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactValidArgs_WithInvalidCount(t *testing.T) {
|
||||||
|
c := getCommand(ExactValidArgs(2), false)
|
||||||
|
_, err := executeCommand(c, "three", "one", "two")
|
||||||
|
exactArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactValidArgs_WithInvalidCount_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactValidArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "three", "a", "two")
|
||||||
|
exactArgsWithInvalidCount(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestExactValidArgs_WithInvalidArgs(t *testing.T) {
|
||||||
|
c := getCommand(ExactValidArgs(2), true)
|
||||||
|
_, err := executeCommand(c, "three", "a")
|
||||||
|
validOnlyWithInvalidArgs(err, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test make sure we keep backwards-compatibility with respect
|
||||||
|
// to the legacyArgs() function.
|
||||||
|
// It makes sure the root command accepts arguments if it does not have
|
||||||
|
// sub-commands.
|
||||||
|
func TestLegacyArgsRootAcceptsArgs(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}
|
||||||
|
|
||||||
|
_, err := executeCommand(rootCmd, "somearg")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test make sure we keep backwards-compatibility with respect
|
||||||
|
// to the legacyArgs() function.
|
||||||
|
// It makes sure a sub-command accepts arguments and further sub-commands
|
||||||
|
func TestLegacyArgsSubcmdAcceptsArgs(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Args: nil, Run: emptyRun}
|
||||||
|
childCmd := &Command{Use: "child", Args: nil, Run: emptyRun}
|
||||||
|
grandchildCmd := &Command{Use: "grandchild", Args: nil, Run: emptyRun}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
childCmd.AddCommand(grandchildCmd)
|
||||||
|
|
||||||
|
_, err := executeCommand(rootCmd, "child", "somearg")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -24,7 +38,7 @@ func writePreamble(buf io.StringWriter, name string) {
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(`
|
WriteStringAndCheck(buf, fmt.Sprintf(`
|
||||||
__%[1]s_debug()
|
__%[1]s_debug()
|
||||||
{
|
{
|
||||||
if [[ -n ${BASH_COMP_DEBUG_FILE} ]]; then
|
if [[ -n ${BASH_COMP_DEBUG_FILE:-} ]]; then
|
||||||
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
|
echo "$*" >> "${BASH_COMP_DEBUG_FILE}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -73,7 +87,8 @@ __%[1]s_handle_go_custom_completion()
|
||||||
# Prepare the command to request completions for the program.
|
# Prepare the command to request completions for the program.
|
||||||
# Calling ${words[0]} instead of directly %[1]s allows to handle aliases
|
# Calling ${words[0]} instead of directly %[1]s allows to handle aliases
|
||||||
args=("${words[@]:1}")
|
args=("${words[@]:1}")
|
||||||
requestComp="${words[0]} %[2]s ${args[*]}"
|
# Disable ActiveHelp which is not supported for bash completion v1
|
||||||
|
requestComp="%[8]s=0 ${words[0]} %[2]s ${args[*]}"
|
||||||
|
|
||||||
lastParam=${words[$((${#words[@]}-1))]}
|
lastParam=${words[$((${#words[@]}-1))]}
|
||||||
lastChar=${lastParam:$((${#lastParam}-1)):1}
|
lastChar=${lastParam:$((${#lastParam}-1)):1}
|
||||||
|
@ -99,7 +114,7 @@ __%[1]s_handle_go_custom_completion()
|
||||||
directive=0
|
directive=0
|
||||||
fi
|
fi
|
||||||
__%[1]s_debug "${FUNCNAME[0]}: the completion directive is: ${directive}"
|
__%[1]s_debug "${FUNCNAME[0]}: the completion directive is: ${directive}"
|
||||||
__%[1]s_debug "${FUNCNAME[0]}: the completions are: ${out[*]}"
|
__%[1]s_debug "${FUNCNAME[0]}: the completions are: ${out}"
|
||||||
|
|
||||||
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
|
||||||
# Error code. No completion.
|
# Error code. No completion.
|
||||||
|
@ -125,7 +140,7 @@ __%[1]s_handle_go_custom_completion()
|
||||||
local fullFilter filter filteringCmd
|
local fullFilter filter filteringCmd
|
||||||
# Do not use quotes around the $out variable or else newline
|
# Do not use quotes around the $out variable or else newline
|
||||||
# characters will be kept.
|
# characters will be kept.
|
||||||
for filter in ${out[*]}; do
|
for filter in ${out}; do
|
||||||
fullFilter+="$filter|"
|
fullFilter+="$filter|"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -134,9 +149,9 @@ __%[1]s_handle_go_custom_completion()
|
||||||
$filteringCmd
|
$filteringCmd
|
||||||
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
||||||
# File completion for directories only
|
# File completion for directories only
|
||||||
local subDir
|
local subdir
|
||||||
# Use printf to strip any trailing newline
|
# Use printf to strip any trailing newline
|
||||||
subdir=$(printf "%%s" "${out[0]}")
|
subdir=$(printf "%%s" "${out}")
|
||||||
if [ -n "$subdir" ]; then
|
if [ -n "$subdir" ]; then
|
||||||
__%[1]s_debug "Listing directories in $subdir"
|
__%[1]s_debug "Listing directories in $subdir"
|
||||||
__%[1]s_handle_subdirs_in_dir_flag "$subdir"
|
__%[1]s_handle_subdirs_in_dir_flag "$subdir"
|
||||||
|
@ -147,7 +162,7 @@ __%[1]s_handle_go_custom_completion()
|
||||||
else
|
else
|
||||||
while IFS='' read -r comp; do
|
while IFS='' read -r comp; do
|
||||||
COMPREPLY+=("$comp")
|
COMPREPLY+=("$comp")
|
||||||
done < <(compgen -W "${out[*]}" -- "$cur")
|
done < <(compgen -W "${out}" -- "$cur")
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,13 +202,19 @@ __%[1]s_handle_reply()
|
||||||
PREFIX=""
|
PREFIX=""
|
||||||
cur="${cur#*=}"
|
cur="${cur#*=}"
|
||||||
${flags_completion[${index}]}
|
${flags_completion[${index}]}
|
||||||
if [ -n "${ZSH_VERSION}" ]; then
|
if [ -n "${ZSH_VERSION:-}" ]; then
|
||||||
# zsh completion needs --flag= prefix
|
# zsh completion needs --flag= prefix
|
||||||
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
|
eval "COMPREPLY=( \"\${COMPREPLY[@]/#/${flag}=}\" )"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z "${flag_parsing_disabled}" ]]; then
|
||||||
|
# If flag parsing is enabled, we have completed the flags and can return.
|
||||||
|
# If flag parsing is disabled, we may not know all (or any) of the flags, so we fallthrough
|
||||||
|
# to possibly call handle_go_custom_completion.
|
||||||
return 0;
|
return 0;
|
||||||
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
@ -272,7 +293,7 @@ __%[1]s_handle_flag()
|
||||||
|
|
||||||
# if a command required a flag, and we found it, unset must_have_one_flag()
|
# if a command required a flag, and we found it, unset must_have_one_flag()
|
||||||
local flagname=${words[c]}
|
local flagname=${words[c]}
|
||||||
local flagvalue
|
local flagvalue=""
|
||||||
# if the word contained an =
|
# if the word contained an =
|
||||||
if [[ ${words[c]} == *"="* ]]; then
|
if [[ ${words[c]} == *"="* ]]; then
|
||||||
flagvalue=${flagname#*=} # take in as flagvalue after the =
|
flagvalue=${flagname#*=} # take in as flagvalue after the =
|
||||||
|
@ -291,7 +312,7 @@ __%[1]s_handle_flag()
|
||||||
|
|
||||||
# keep flag value with flagname as flaghash
|
# keep flag value with flagname as flaghash
|
||||||
# flaghash variable is an associative array which is only supported in bash > 3.
|
# flaghash variable is an associative array which is only supported in bash > 3.
|
||||||
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
|
if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
|
||||||
if [ -n "${flagvalue}" ] ; then
|
if [ -n "${flagvalue}" ] ; then
|
||||||
flaghash[${flagname}]=${flagvalue}
|
flaghash[${flagname}]=${flagvalue}
|
||||||
elif [ -n "${words[ $((c+1)) ]}" ] ; then
|
elif [ -n "${words[ $((c+1)) ]}" ] ; then
|
||||||
|
@ -363,7 +384,7 @@ __%[1]s_handle_word()
|
||||||
__%[1]s_handle_command
|
__%[1]s_handle_command
|
||||||
elif __%[1]s_contains_word "${words[c]}" "${command_aliases[@]}"; then
|
elif __%[1]s_contains_word "${words[c]}" "${command_aliases[@]}"; then
|
||||||
# aliashash variable is an associative array which is only supported in bash > 3.
|
# aliashash variable is an associative array which is only supported in bash > 3.
|
||||||
if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then
|
if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then
|
||||||
words[c]=${aliashash[${words[c]}]}
|
words[c]=${aliashash[${words[c]}]}
|
||||||
__%[1]s_handle_command
|
__%[1]s_handle_command
|
||||||
else
|
else
|
||||||
|
@ -377,11 +398,11 @@ __%[1]s_handle_word()
|
||||||
|
|
||||||
`, name, ShellCompNoDescRequestCmd,
|
`, name, ShellCompNoDescRequestCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func writePostscript(buf io.StringWriter, name string) {
|
func writePostscript(buf io.StringWriter, name string) {
|
||||||
name = strings.Replace(name, ":", "__", -1)
|
name = strings.ReplaceAll(name, ":", "__")
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf("__start_%s()\n", name))
|
WriteStringAndCheck(buf, fmt.Sprintf("__start_%s()\n", name))
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(`{
|
WriteStringAndCheck(buf, fmt.Sprintf(`{
|
||||||
local cur prev words cword split
|
local cur prev words cword split
|
||||||
|
@ -394,6 +415,7 @@ func writePostscript(buf io.StringWriter, name string) {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local c=0
|
local c=0
|
||||||
|
local flag_parsing_disabled=
|
||||||
local flags=()
|
local flags=()
|
||||||
local two_word_flags=()
|
local two_word_flags=()
|
||||||
local local_nonpersistent_flags=()
|
local local_nonpersistent_flags=()
|
||||||
|
@ -403,8 +425,8 @@ func writePostscript(buf io.StringWriter, name string) {
|
||||||
local command_aliases=()
|
local command_aliases=()
|
||||||
local must_have_one_flag=()
|
local must_have_one_flag=()
|
||||||
local must_have_one_noun=()
|
local must_have_one_noun=()
|
||||||
local has_completion_function
|
local has_completion_function=""
|
||||||
local last_command
|
local last_command=""
|
||||||
local nouns=()
|
local nouns=()
|
||||||
local noun_aliases=()
|
local noun_aliases=()
|
||||||
|
|
||||||
|
@ -535,6 +557,11 @@ func writeFlags(buf io.StringWriter, cmd *Command) {
|
||||||
flags_completion=()
|
flags_completion=()
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
if cmd.DisableFlagParsing {
|
||||||
|
WriteStringAndCheck(buf, " flag_parsing_disabled=1\n")
|
||||||
|
}
|
||||||
|
|
||||||
localNonPersistentFlags := cmd.LocalNonPersistentFlags()
|
localNonPersistentFlags := cmd.LocalNonPersistentFlags()
|
||||||
cmd.NonInheritedFlags().VisitAll(func(flag *pflag.Flag) {
|
cmd.NonInheritedFlags().VisitAll(func(flag *pflag.Flag) {
|
||||||
if nonCompletableFlag(flag) {
|
if nonCompletableFlag(flag) {
|
||||||
|
@ -609,7 +636,7 @@ func writeCmdAliases(buf io.StringWriter, cmd *Command) {
|
||||||
|
|
||||||
sort.Strings(cmd.Aliases)
|
sort.Strings(cmd.Aliases)
|
||||||
|
|
||||||
WriteStringAndCheck(buf, fmt.Sprint(` if [[ -z "${BASH_VERSION}" || "${BASH_VERSINFO[0]}" -gt 3 ]]; then`, "\n"))
|
WriteStringAndCheck(buf, fmt.Sprint(` if [[ -z "${BASH_VERSION:-}" || "${BASH_VERSINFO[0]:-}" -gt 3 ]]; then`, "\n"))
|
||||||
for _, value := range cmd.Aliases {
|
for _, value := range cmd.Aliases {
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(" command_aliases+=(%q)\n", value))
|
WriteStringAndCheck(buf, fmt.Sprintf(" command_aliases+=(%q)\n", value))
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(" aliashash[%q]=%q\n", value, cmd.Name()))
|
WriteStringAndCheck(buf, fmt.Sprintf(" aliashash[%q]=%q\n", value, cmd.Name()))
|
||||||
|
@ -633,8 +660,8 @@ func gen(buf io.StringWriter, cmd *Command) {
|
||||||
gen(buf, c)
|
gen(buf, c)
|
||||||
}
|
}
|
||||||
commandName := cmd.CommandPath()
|
commandName := cmd.CommandPath()
|
||||||
commandName = strings.Replace(commandName, " ", "_", -1)
|
commandName = strings.ReplaceAll(commandName, " ", "_")
|
||||||
commandName = strings.Replace(commandName, ":", "__", -1)
|
commandName = strings.ReplaceAll(commandName, ":", "__")
|
||||||
|
|
||||||
if cmd.Root() == cmd {
|
if cmd.Root() == cmd {
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf("_%s_root_command()\n{\n", commandName))
|
WriteStringAndCheck(buf, fmt.Sprintf("_%s_root_command()\n{\n", commandName))
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -78,7 +92,7 @@ __%[1]s_get_completion_results() {
|
||||||
directive=0
|
directive=0
|
||||||
fi
|
fi
|
||||||
__%[1]s_debug "The completion directive is: ${directive}"
|
__%[1]s_debug "The completion directive is: ${directive}"
|
||||||
__%[1]s_debug "The completions are: ${out[*]}"
|
__%[1]s_debug "The completions are: ${out}"
|
||||||
}
|
}
|
||||||
|
|
||||||
__%[1]s_process_completion_results() {
|
__%[1]s_process_completion_results() {
|
||||||
|
@ -111,13 +125,18 @@ __%[1]s_process_completion_results() {
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Separate activeHelp from normal completions
|
||||||
|
local completions=()
|
||||||
|
local activeHelp=()
|
||||||
|
__%[1]s_extract_activeHelp
|
||||||
|
|
||||||
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
|
||||||
# File extension filtering
|
# File extension filtering
|
||||||
local fullFilter filter filteringCmd
|
local fullFilter filter filteringCmd
|
||||||
|
|
||||||
# Do not use quotes around the $out variable or else newline
|
# Do not use quotes around the $completions variable or else newline
|
||||||
# characters will be kept.
|
# characters will be kept.
|
||||||
for filter in ${out[*]}; do
|
for filter in ${completions[*]}; do
|
||||||
fullFilter+="$filter|"
|
fullFilter+="$filter|"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
@ -129,7 +148,7 @@ __%[1]s_process_completion_results() {
|
||||||
|
|
||||||
# Use printf to strip any trailing newline
|
# Use printf to strip any trailing newline
|
||||||
local subdir
|
local subdir
|
||||||
subdir=$(printf "%%s" "${out[0]}")
|
subdir=$(printf "%%s" "${completions[0]}")
|
||||||
if [ -n "$subdir" ]; then
|
if [ -n "$subdir" ]; then
|
||||||
__%[1]s_debug "Listing directories in $subdir"
|
__%[1]s_debug "Listing directories in $subdir"
|
||||||
pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
|
pushd "$subdir" >/dev/null 2>&1 && _filedir -d && popd >/dev/null 2>&1 || return
|
||||||
|
@ -138,52 +157,110 @@ __%[1]s_process_completion_results() {
|
||||||
_filedir -d
|
_filedir -d
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
__%[1]s_handle_standard_completion_case
|
__%[1]s_handle_completion_types
|
||||||
fi
|
fi
|
||||||
|
|
||||||
__%[1]s_handle_special_char "$cur" :
|
__%[1]s_handle_special_char "$cur" :
|
||||||
__%[1]s_handle_special_char "$cur" =
|
__%[1]s_handle_special_char "$cur" =
|
||||||
|
|
||||||
|
# Print the activeHelp statements before we finish
|
||||||
|
if [ ${#activeHelp[*]} -ne 0 ]; then
|
||||||
|
printf "\n";
|
||||||
|
printf "%%s\n" "${activeHelp[@]}"
|
||||||
|
printf "\n"
|
||||||
|
|
||||||
|
# The prompt format is only available from bash 4.4.
|
||||||
|
# We test if it is available before using it.
|
||||||
|
if (x=${PS1@P}) 2> /dev/null; then
|
||||||
|
printf "%%s" "${PS1@P}${COMP_LINE[@]}"
|
||||||
|
else
|
||||||
|
# Can't print the prompt. Just print the
|
||||||
|
# text the user had typed, it is workable enough.
|
||||||
|
printf "%%s" "${COMP_LINE[@]}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Separate activeHelp lines from real completions.
|
||||||
|
# Fills the $activeHelp and $completions arrays.
|
||||||
|
__%[1]s_extract_activeHelp() {
|
||||||
|
local activeHelpMarker="%[8]s"
|
||||||
|
local endIndex=${#activeHelpMarker}
|
||||||
|
|
||||||
|
while IFS='' read -r comp; do
|
||||||
|
if [ "${comp:0:endIndex}" = "$activeHelpMarker" ]; then
|
||||||
|
comp=${comp:endIndex}
|
||||||
|
__%[1]s_debug "ActiveHelp found: $comp"
|
||||||
|
if [ -n "$comp" ]; then
|
||||||
|
activeHelp+=("$comp")
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# Not an activeHelp line but a normal completion
|
||||||
|
completions+=("$comp")
|
||||||
|
fi
|
||||||
|
done < <(printf "%%s\n" "${out}")
|
||||||
|
}
|
||||||
|
|
||||||
|
__%[1]s_handle_completion_types() {
|
||||||
|
__%[1]s_debug "__%[1]s_handle_completion_types: COMP_TYPE is $COMP_TYPE"
|
||||||
|
|
||||||
|
case $COMP_TYPE in
|
||||||
|
37|42)
|
||||||
|
# Type: menu-complete/menu-complete-backward and insert-completions
|
||||||
|
# If the user requested inserting one completion at a time, or all
|
||||||
|
# completions at once on the command-line we must remove the descriptions.
|
||||||
|
# https://github.com/spf13/cobra/issues/1508
|
||||||
|
local tab=$'\t' comp
|
||||||
|
while IFS='' read -r comp; do
|
||||||
|
[[ -z $comp ]] && continue
|
||||||
|
# Strip any description
|
||||||
|
comp=${comp%%%%$tab*}
|
||||||
|
# Only consider the completions that match
|
||||||
|
if [[ $comp == "$cur"* ]]; then
|
||||||
|
COMPREPLY+=("$comp")
|
||||||
|
fi
|
||||||
|
done < <(printf "%%s\n" "${completions[@]}")
|
||||||
|
;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# Type: complete (normal completion)
|
||||||
|
__%[1]s_handle_standard_completion_case
|
||||||
|
;;
|
||||||
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
__%[1]s_handle_standard_completion_case() {
|
__%[1]s_handle_standard_completion_case() {
|
||||||
local tab comp
|
local tab=$'\t' comp
|
||||||
tab=$(printf '\t')
|
|
||||||
|
# Short circuit to optimize if we don't have descriptions
|
||||||
|
if [[ "${completions[*]}" != *$tab* ]]; then
|
||||||
|
IFS=$'\n' read -ra COMPREPLY -d '' < <(compgen -W "${completions[*]}" -- "$cur")
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
local longest=0
|
local longest=0
|
||||||
|
local compline
|
||||||
# Look for the longest completion so that we can format things nicely
|
# Look for the longest completion so that we can format things nicely
|
||||||
while IFS='' read -r comp; do
|
while IFS='' read -r compline; do
|
||||||
|
[[ -z $compline ]] && continue
|
||||||
# Strip any description before checking the length
|
# Strip any description before checking the length
|
||||||
comp=${comp%%%%$tab*}
|
comp=${compline%%%%$tab*}
|
||||||
# Only consider the completions that match
|
# Only consider the completions that match
|
||||||
comp=$(compgen -W "$comp" -- "$cur")
|
[[ $comp == "$cur"* ]] || continue
|
||||||
|
COMPREPLY+=("$compline")
|
||||||
if ((${#comp}>longest)); then
|
if ((${#comp}>longest)); then
|
||||||
longest=${#comp}
|
longest=${#comp}
|
||||||
fi
|
fi
|
||||||
done < <(printf "%%s\n" "${out[@]}")
|
done < <(printf "%%s\n" "${completions[@]}")
|
||||||
|
|
||||||
local completions=()
|
|
||||||
while IFS='' read -r comp; do
|
|
||||||
if [ -z "$comp" ]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
__%[1]s_debug "Original comp: $comp"
|
|
||||||
comp="$(__%[1]s_format_comp_descriptions "$comp" "$longest")"
|
|
||||||
__%[1]s_debug "Final comp: $comp"
|
|
||||||
completions+=("$comp")
|
|
||||||
done < <(printf "%%s\n" "${out[@]}")
|
|
||||||
|
|
||||||
while IFS='' read -r comp; do
|
|
||||||
COMPREPLY+=("$comp")
|
|
||||||
done < <(compgen -W "${completions[*]}" -- "$cur")
|
|
||||||
|
|
||||||
# If there is a single completion left, remove the description text
|
# If there is a single completion left, remove the description text
|
||||||
if [ ${#COMPREPLY[*]} -eq 1 ]; then
|
if [ ${#COMPREPLY[*]} -eq 1 ]; then
|
||||||
__%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
|
__%[1]s_debug "COMPREPLY[0]: ${COMPREPLY[0]}"
|
||||||
comp="${COMPREPLY[0]%%%% *}"
|
comp="${COMPREPLY[0]%%%%$tab*}"
|
||||||
__%[1]s_debug "Removed description from single completion, which is now: ${comp}"
|
__%[1]s_debug "Removed description from single completion, which is now: ${comp}"
|
||||||
COMPREPLY=()
|
COMPREPLY[0]=$comp
|
||||||
COMPREPLY+=("$comp")
|
else # Format the descriptions
|
||||||
|
__%[1]s_format_comp_descriptions $longest
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,13 +279,16 @@ __%[1]s_handle_special_char()
|
||||||
|
|
||||||
__%[1]s_format_comp_descriptions()
|
__%[1]s_format_comp_descriptions()
|
||||||
{
|
{
|
||||||
local tab
|
local tab=$'\t'
|
||||||
tab=$(printf '\t')
|
local comp desc maxdesclength
|
||||||
local comp="$1"
|
local longest=$1
|
||||||
local longest=$2
|
|
||||||
|
|
||||||
|
local i ci
|
||||||
|
for ci in ${!COMPREPLY[*]}; do
|
||||||
|
comp=${COMPREPLY[ci]}
|
||||||
# Properly format the description string which follows a tab character if there is one
|
# Properly format the description string which follows a tab character if there is one
|
||||||
if [[ "$comp" == *$tab* ]]; then
|
if [[ "$comp" == *$tab* ]]; then
|
||||||
|
__%[1]s_debug "Original comp: $comp"
|
||||||
desc=${comp#*$tab}
|
desc=${comp#*$tab}
|
||||||
comp=${comp%%%%$tab*}
|
comp=${comp%%%%$tab*}
|
||||||
|
|
||||||
|
@ -237,10 +317,10 @@ __%[1]s_format_comp_descriptions()
|
||||||
fi
|
fi
|
||||||
comp+=" ($desc)"
|
comp+=" ($desc)"
|
||||||
fi
|
fi
|
||||||
|
COMPREPLY[ci]=$comp
|
||||||
|
__%[1]s_debug "Final comp: $comp"
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
# Must use printf to escape all special characters
|
|
||||||
printf "%%q" "${comp}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__start_%[1]s()
|
__start_%[1]s()
|
||||||
|
@ -281,7 +361,8 @@ fi
|
||||||
# ex: ts=4 sw=4 et filetype=sh
|
# ex: ts=4 sw=4 et filetype=sh
|
||||||
`, name, compCmd,
|
`, name, compCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs,
|
||||||
|
activeHelpMarker))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenBashCompletionFileV2 generates Bash completion version 2.
|
// GenBashCompletionFileV2 generates Bash completion version 2.
|
||||||
|
|
33
bash_completionsV2_test.go
Normal file
33
bash_completionsV2_test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestBashCompletionV2WithActiveHelp(t *testing.T) {
|
||||||
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
assertNoErr(t, c.GenBashCompletionV2(buf, true))
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
// check that active help is not being disabled
|
||||||
|
activeHelpVar := activeHelpEnvVar(c.Name())
|
||||||
|
checkOmit(t, output, fmt.Sprintf("%s=0", activeHelpVar))
|
||||||
|
}
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -261,3 +275,15 @@ func TestBashCompletionTraverseChildren(t *testing.T) {
|
||||||
checkOmit(t, output, `local_nonpersistent_flags+=("--bool-flag")`)
|
checkOmit(t, output, `local_nonpersistent_flags+=("--bool-flag")`)
|
||||||
checkOmit(t, output, `local_nonpersistent_flags+=("-b")`)
|
checkOmit(t, output, `local_nonpersistent_flags+=("-b")`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBashCompletionNoActiveHelp(t *testing.T) {
|
||||||
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
assertNoErr(t, c.GenBashCompletion(buf))
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
// check that active help is being disabled
|
||||||
|
activeHelpVar := activeHelpEnvVar(c.Name())
|
||||||
|
check(t, output, fmt.Sprintf("%s=0", activeHelpVar))
|
||||||
|
}
|
||||||
|
|
23
cobra.go
23
cobra.go
|
@ -1,8 +1,9 @@
|
||||||
// Copyright © 2013 Steve Francia <spf@spf13.com>.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -39,15 +40,25 @@ var templateFuncs = template.FuncMap{
|
||||||
}
|
}
|
||||||
|
|
||||||
var initializers []func()
|
var initializers []func()
|
||||||
|
var finalizers []func()
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultPrefixMatching = false
|
||||||
|
defaultCommandSorting = true
|
||||||
|
defaultCaseInsensitive = false
|
||||||
|
)
|
||||||
|
|
||||||
// EnablePrefixMatching allows to set automatic prefix matching. Automatic prefix matching can be a dangerous thing
|
// EnablePrefixMatching allows to set automatic prefix matching. Automatic prefix matching can be a dangerous thing
|
||||||
// to automatically enable in CLI tools.
|
// to automatically enable in CLI tools.
|
||||||
// Set this to true to enable it.
|
// Set this to true to enable it.
|
||||||
var EnablePrefixMatching = false
|
var EnablePrefixMatching = defaultPrefixMatching
|
||||||
|
|
||||||
// EnableCommandSorting controls sorting of the slice of commands, which is turned on by default.
|
// EnableCommandSorting controls sorting of the slice of commands, which is turned on by default.
|
||||||
// To disable sorting, set it to false.
|
// To disable sorting, set it to false.
|
||||||
var EnableCommandSorting = true
|
var EnableCommandSorting = defaultCommandSorting
|
||||||
|
|
||||||
|
// EnableCaseInsensitive allows case-insensitive commands names. (case sensitive by default)
|
||||||
|
var EnableCaseInsensitive = defaultCaseInsensitive
|
||||||
|
|
||||||
// MousetrapHelpText enables an information splash screen on Windows
|
// MousetrapHelpText enables an information splash screen on Windows
|
||||||
// if the CLI is started from explorer.exe.
|
// if the CLI is started from explorer.exe.
|
||||||
|
@ -84,6 +95,12 @@ func OnInitialize(y ...func()) {
|
||||||
initializers = append(initializers, y...)
|
initializers = append(initializers, y...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// OnFinalize sets the passed functions to be run when each command's
|
||||||
|
// Execute method is terminated.
|
||||||
|
func OnFinalize(y ...func()) {
|
||||||
|
finalizers = append(finalizers, y...)
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME Gt is unused by cobra and should be removed in a version 2. It exists only for compatibility with users of cobra.
|
// FIXME Gt is unused by cobra and should be removed in a version 2. It exists only for compatibility with users of cobra.
|
||||||
|
|
||||||
// Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,
|
// Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans,
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
XC_OS="linux darwin"
|
|
||||||
XC_ARCH="amd64"
|
|
||||||
XC_PARALLEL="2"
|
|
||||||
BIN="../bin"
|
|
||||||
SRC=$(shell find . -name "*.go")
|
|
||||||
|
|
||||||
ifeq (, $(shell which gox))
|
|
||||||
$(warning "could not find gox in $(PATH), run: go get github.com/mitchellh/gox")
|
|
||||||
endif
|
|
||||||
|
|
||||||
.PHONY: all build
|
|
||||||
|
|
||||||
default: all
|
|
||||||
|
|
||||||
all: build
|
|
||||||
|
|
||||||
build:
|
|
||||||
gox \
|
|
||||||
-os=$(XC_OS) \
|
|
||||||
-arch=$(XC_ARCH) \
|
|
||||||
-parallel=$(XC_PARALLEL) \
|
|
||||||
-output=$(BIN)/{{.Dir}}_{{.OS}}_{{.Arch}} \
|
|
||||||
;
|
|
129
cobra/README.md
129
cobra/README.md
|
@ -1,129 +0,0 @@
|
||||||
# Cobra Generator
|
|
||||||
|
|
||||||
Cobra provides its own program that will create your application and add any
|
|
||||||
commands you want. It's the easiest way to incorporate Cobra into your application.
|
|
||||||
|
|
||||||
In order to use the cobra command, compile it using the following command:
|
|
||||||
|
|
||||||
go get github.com/spf13/cobra/cobra
|
|
||||||
|
|
||||||
This will create the cobra executable under your `$GOPATH/bin` directory.
|
|
||||||
|
|
||||||
### cobra init
|
|
||||||
|
|
||||||
The `cobra init [app]` command will create your initial application code
|
|
||||||
for you. It is a very powerful application that will populate your program with
|
|
||||||
the right structure so you can immediately enjoy all the benefits of Cobra. It
|
|
||||||
will also automatically apply the license you specify to your application.
|
|
||||||
|
|
||||||
Cobra init is pretty smart. You can either run it in your current application directory
|
|
||||||
or you can specify a relative path to an existing project. If the directory does not exist, it will be created for you.
|
|
||||||
|
|
||||||
Updates to the Cobra generator have now decoupled it from the GOPATH.
|
|
||||||
As such `--pkg-name` is required.
|
|
||||||
|
|
||||||
**Note:** init will no longer fail on non-empty directories.
|
|
||||||
|
|
||||||
```
|
|
||||||
mkdir -p newApp && cd newApp
|
|
||||||
cobra init --pkg-name github.com/spf13/newApp
|
|
||||||
```
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
```
|
|
||||||
cobra init --pkg-name github.com/spf13/newApp path/to/newApp
|
|
||||||
```
|
|
||||||
|
|
||||||
### cobra add
|
|
||||||
|
|
||||||
Once an application is initialized, Cobra can create additional commands for you.
|
|
||||||
Let's say you created an app and you wanted the following commands for it:
|
|
||||||
|
|
||||||
* app serve
|
|
||||||
* app config
|
|
||||||
* app config create
|
|
||||||
|
|
||||||
In your project directory (where your main.go file is) you would run the following:
|
|
||||||
|
|
||||||
```
|
|
||||||
cobra add serve
|
|
||||||
cobra add config
|
|
||||||
cobra add create -p 'configCmd'
|
|
||||||
```
|
|
||||||
|
|
||||||
*Note: Use camelCase (not snake_case/kebab-case) for command names.
|
|
||||||
Otherwise, you will encounter errors.
|
|
||||||
For example, `cobra add add-user` is incorrect, but `cobra add addUser` is valid.*
|
|
||||||
|
|
||||||
Once you have run these three commands you would have an app structure similar to
|
|
||||||
the following:
|
|
||||||
|
|
||||||
```
|
|
||||||
▾ app/
|
|
||||||
▾ cmd/
|
|
||||||
serve.go
|
|
||||||
config.go
|
|
||||||
create.go
|
|
||||||
main.go
|
|
||||||
```
|
|
||||||
|
|
||||||
At this point you can run `go run main.go` and it would run your app. `go run
|
|
||||||
main.go serve`, `go run main.go config`, `go run main.go config create` along
|
|
||||||
with `go run main.go help serve`, etc. would all work.
|
|
||||||
|
|
||||||
Obviously you haven't added your own code to these yet. The commands are ready
|
|
||||||
for you to give them their tasks. Have fun!
|
|
||||||
|
|
||||||
### Configuring the cobra generator
|
|
||||||
|
|
||||||
The Cobra generator will be easier to use if you provide a simple configuration
|
|
||||||
file which will help you eliminate providing a bunch of repeated information in
|
|
||||||
flags over and over.
|
|
||||||
|
|
||||||
An example ~/.cobra.yaml file:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
author: Steve Francia <spf@spf13.com>
|
|
||||||
license: MIT
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use built-in licenses. For example, **GPLv2**, **GPLv3**, **LGPL**,
|
|
||||||
**AGPL**, **MIT**, **2-Clause BSD** or **3-Clause BSD**.
|
|
||||||
|
|
||||||
You can specify no license by setting `license` to `none` or you can specify
|
|
||||||
a custom license:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
author: Steve Francia <spf@spf13.com>
|
|
||||||
year: 2020
|
|
||||||
license:
|
|
||||||
header: This file is part of CLI application foo.
|
|
||||||
text: |
|
|
||||||
{{ .copyright }}
|
|
||||||
|
|
||||||
This is my license. There are many like it, but this one is mine.
|
|
||||||
My license is my best friend. It is my life. I must master it as I must
|
|
||||||
master my life.
|
|
||||||
```
|
|
||||||
|
|
||||||
In the above custom license configuration the `copyright` line in the License
|
|
||||||
text is generated from the `author` and `year` properties. The content of the
|
|
||||||
`LICENSE` file is
|
|
||||||
|
|
||||||
```
|
|
||||||
Copyright © 2020 Steve Francia <spf@spf13.com>
|
|
||||||
|
|
||||||
This is my license. There are many like it, but this one is mine.
|
|
||||||
My license is my best friend. It is my life. I must master it as I must
|
|
||||||
master my life.
|
|
||||||
```
|
|
||||||
|
|
||||||
The `header` property is used as the license header files. No interpolation is
|
|
||||||
done. This is the example of the go file header.
|
|
||||||
```
|
|
||||||
/*
|
|
||||||
Copyright © 2020 Steve Francia <spf@spf13.com>
|
|
||||||
This file is part of CLI application foo.
|
|
||||||
*/
|
|
||||||
```
|
|
124
cobra/cmd/add.go
124
cobra/cmd/add.go
|
@ -1,124 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"unicode"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
packageName string
|
|
||||||
parentName string
|
|
||||||
|
|
||||||
addCmd = &cobra.Command{
|
|
||||||
Use: "add [command name]",
|
|
||||||
Aliases: []string{"command"},
|
|
||||||
Short: "Add a command to a Cobra Application",
|
|
||||||
Long: `Add (cobra add) will create a new command, with a license and
|
|
||||||
the appropriate structure for a Cobra-based CLI application,
|
|
||||||
and register it to its parent (default rootCmd).
|
|
||||||
|
|
||||||
If you want your command to be public, pass in the command name
|
|
||||||
with an initial uppercase letter.
|
|
||||||
|
|
||||||
Example: cobra add server -> resulting in a new cmd/server.go`,
|
|
||||||
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
if len(args) < 1 {
|
|
||||||
cobra.CheckErr(fmt.Errorf("add needs a name for the command"))
|
|
||||||
}
|
|
||||||
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
commandName := validateCmdName(args[0])
|
|
||||||
command := &Command{
|
|
||||||
CmdName: commandName,
|
|
||||||
CmdParent: parentName,
|
|
||||||
Project: &Project{
|
|
||||||
AbsolutePath: wd,
|
|
||||||
Legal: getLicense(),
|
|
||||||
Copyright: copyrightLine(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
cobra.CheckErr(command.Create())
|
|
||||||
|
|
||||||
fmt.Printf("%s created at %s\n", command.CmdName, command.AbsolutePath)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
addCmd.Flags().StringVarP(&packageName, "package", "t", "", "target package name (e.g. github.com/spf13/hugo)")
|
|
||||||
addCmd.Flags().StringVarP(&parentName, "parent", "p", "rootCmd", "variable name of parent command for this command")
|
|
||||||
cobra.CheckErr(addCmd.Flags().MarkDeprecated("package", "this operation has been removed."))
|
|
||||||
}
|
|
||||||
|
|
||||||
// validateCmdName returns source without any dashes and underscore.
|
|
||||||
// If there will be dash or underscore, next letter will be uppered.
|
|
||||||
// It supports only ASCII (1-byte character) strings.
|
|
||||||
// https://github.com/spf13/cobra/issues/269
|
|
||||||
func validateCmdName(source string) string {
|
|
||||||
i := 0
|
|
||||||
l := len(source)
|
|
||||||
// The output is initialized on demand, then first dash or underscore
|
|
||||||
// occurs.
|
|
||||||
var output string
|
|
||||||
|
|
||||||
for i < l {
|
|
||||||
if source[i] == '-' || source[i] == '_' {
|
|
||||||
if output == "" {
|
|
||||||
output = source[:i]
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it's last rune and it's dash or underscore,
|
|
||||||
// don't add it output and break the loop.
|
|
||||||
if i == l-1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
// If next character is dash or underscore,
|
|
||||||
// just skip the current character.
|
|
||||||
if source[i+1] == '-' || source[i+1] == '_' {
|
|
||||||
i++
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the current character is dash or underscore,
|
|
||||||
// upper next letter and add to output.
|
|
||||||
output += string(unicode.ToUpper(rune(source[i+1])))
|
|
||||||
// We know, what source[i] is dash or underscore and source[i+1] is
|
|
||||||
// uppered character, so make i = i+2.
|
|
||||||
i += 2
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the current character isn't dash or underscore,
|
|
||||||
// just add it.
|
|
||||||
if output != "" {
|
|
||||||
output += string(source[i])
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
|
|
||||||
if output == "" {
|
|
||||||
return source // source is initially valid name.
|
|
||||||
}
|
|
||||||
return output
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestGoldenAddCmd(t *testing.T) {
|
|
||||||
command := &Command{
|
|
||||||
CmdName: "test",
|
|
||||||
CmdParent: parentName,
|
|
||||||
Project: getProject(),
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(command.AbsolutePath)
|
|
||||||
|
|
||||||
assertNoErr(t, command.Project.Create())
|
|
||||||
assertNoErr(t, command.Create())
|
|
||||||
|
|
||||||
generatedFile := fmt.Sprintf("%s/cmd/%s.go", command.AbsolutePath, command.CmdName)
|
|
||||||
goldenFile := fmt.Sprintf("testdata/%s.go.golden", command.CmdName)
|
|
||||||
err := compareFiles(generatedFile, goldenFile)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestValidateCmdName(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
input string
|
|
||||||
expected string
|
|
||||||
}{
|
|
||||||
{"cmdName", "cmdName"},
|
|
||||||
{"cmd_name", "cmdName"},
|
|
||||||
{"cmd-name", "cmdName"},
|
|
||||||
{"cmd______Name", "cmdName"},
|
|
||||||
{"cmd------Name", "cmdName"},
|
|
||||||
{"cmd______name", "cmdName"},
|
|
||||||
{"cmd------name", "cmdName"},
|
|
||||||
{"cmdName-----", "cmdName"},
|
|
||||||
{"cmdname-", "cmdname"},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
|
||||||
got := validateCmdName(testCase.input)
|
|
||||||
if testCase.expected != got {
|
|
||||||
t.Errorf("Expected %q, got %q", testCase.expected, got)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os/exec"
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Mute commands.
|
|
||||||
addCmd.SetOut(new(bytes.Buffer))
|
|
||||||
addCmd.SetErr(new(bytes.Buffer))
|
|
||||||
initCmd.SetOut(new(bytes.Buffer))
|
|
||||||
initCmd.SetErr(new(bytes.Buffer))
|
|
||||||
}
|
|
||||||
|
|
||||||
// ensureLF converts any \r\n to \n
|
|
||||||
func ensureLF(content []byte) []byte {
|
|
||||||
return bytes.Replace(content, []byte("\r\n"), []byte("\n"), -1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// compareFiles compares the content of files with pathA and pathB.
|
|
||||||
// If contents are equal, it returns nil.
|
|
||||||
// If not, it returns which files are not equal
|
|
||||||
// and diff (if system has diff command) between these files.
|
|
||||||
func compareFiles(pathA, pathB string) error {
|
|
||||||
contentA, err := ioutil.ReadFile(pathA)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
contentB, err := ioutil.ReadFile(pathB)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !bytes.Equal(ensureLF(contentA), ensureLF(contentB)) {
|
|
||||||
output := new(bytes.Buffer)
|
|
||||||
output.WriteString(fmt.Sprintf("%q and %q are not equal!\n\n", pathA, pathB))
|
|
||||||
|
|
||||||
diffPath, err := exec.LookPath("diff")
|
|
||||||
if err != nil {
|
|
||||||
// Don't execute diff if it can't be found.
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
diffCmd := exec.Command(diffPath, "-u", pathA, pathB)
|
|
||||||
diffCmd.Stdout = output
|
|
||||||
diffCmd.Stderr = output
|
|
||||||
|
|
||||||
output.WriteString("$ diff -u " + pathA + " " + pathB + "\n")
|
|
||||||
if err := diffCmd.Run(); err != nil {
|
|
||||||
output.WriteString("\n" + err.Error())
|
|
||||||
}
|
|
||||||
return errors.New(output.String())
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,56 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
var srcPaths []string
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Initialize srcPaths.
|
|
||||||
envGoPath := os.Getenv("GOPATH")
|
|
||||||
goPaths := filepath.SplitList(envGoPath)
|
|
||||||
if len(goPaths) == 0 {
|
|
||||||
// Adapted from https://github.com/Masterminds/glide/pull/798/files.
|
|
||||||
// As of Go 1.8 the GOPATH is no longer required to be set. Instead there
|
|
||||||
// is a default value. If there is no GOPATH check for the default value.
|
|
||||||
// Note, checking the GOPATH first to avoid invoking the go toolchain if
|
|
||||||
// possible.
|
|
||||||
|
|
||||||
goExecutable := os.Getenv("COBRA_GO_EXECUTABLE")
|
|
||||||
if len(goExecutable) <= 0 {
|
|
||||||
goExecutable = "go"
|
|
||||||
}
|
|
||||||
|
|
||||||
out, err := exec.Command(goExecutable, "env", "GOPATH").Output()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
toolchainGoPath := strings.TrimSpace(string(out))
|
|
||||||
goPaths = filepath.SplitList(toolchainGoPath)
|
|
||||||
if len(goPaths) == 0 {
|
|
||||||
cobra.CheckErr("$GOPATH is not set")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
srcPaths = make([]string, 0, len(goPaths))
|
|
||||||
for _, goPath := range goPaths {
|
|
||||||
srcPaths = append(srcPaths, filepath.Join(goPath, "src"))
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func assertNoErr(t *testing.T, e error) {
|
|
||||||
if e != nil {
|
|
||||||
t.Error(e)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,79 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
pkgName string
|
|
||||||
|
|
||||||
initCmd = &cobra.Command{
|
|
||||||
Use: "init [name]",
|
|
||||||
Aliases: []string{"initialize", "initialise", "create"},
|
|
||||||
Short: "Initialize a Cobra Application",
|
|
||||||
Long: `Initialize (cobra init) will create a new application, with a license
|
|
||||||
and the appropriate structure for a Cobra-based CLI application.
|
|
||||||
|
|
||||||
* If a name is provided, a directory with that name will be created in the current directory;
|
|
||||||
* If no name is provided, the current directory will be assumed;
|
|
||||||
`,
|
|
||||||
|
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
|
||||||
|
|
||||||
projectPath, err := initializeProject(args)
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
fmt.Printf("Your Cobra application is ready at\n%s\n", projectPath)
|
|
||||||
},
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
initCmd.Flags().StringVar(&pkgName, "pkg-name", "", "fully qualified pkg name")
|
|
||||||
cobra.CheckErr(initCmd.MarkFlagRequired("pkg-name"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func initializeProject(args []string) (string, error) {
|
|
||||||
wd, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) > 0 {
|
|
||||||
if args[0] != "." {
|
|
||||||
wd = fmt.Sprintf("%s/%s", wd, args[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
project := &Project{
|
|
||||||
AbsolutePath: wd,
|
|
||||||
PkgName: pkgName,
|
|
||||||
Legal: getLicense(),
|
|
||||||
Copyright: copyrightLine(),
|
|
||||||
Viper: viper.GetBool("useViper"),
|
|
||||||
AppName: path.Base(pkgName),
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := project.Create(); err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return project.AbsolutePath, nil
|
|
||||||
}
|
|
|
@ -1,94 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getProject() *Project {
|
|
||||||
wd, _ := os.Getwd()
|
|
||||||
return &Project{
|
|
||||||
AbsolutePath: fmt.Sprintf("%s/testproject", wd),
|
|
||||||
Legal: getLicense(),
|
|
||||||
Copyright: copyrightLine(),
|
|
||||||
AppName: "testproject",
|
|
||||||
PkgName: "github.com/spf13/testproject",
|
|
||||||
Viper: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGoldenInitCmd(t *testing.T) {
|
|
||||||
|
|
||||||
dir, err := ioutil.TempDir("", "cobra-init")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(dir)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
args []string
|
|
||||||
pkgName string
|
|
||||||
expectErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "successfully creates a project with name",
|
|
||||||
args: []string{"testproject"},
|
|
||||||
pkgName: "github.com/spf13/testproject",
|
|
||||||
expectErr: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "returns error when passing an absolute path for project",
|
|
||||||
args: []string{dir},
|
|
||||||
pkgName: "github.com/spf13/testproject",
|
|
||||||
expectErr: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "returns error when passing a relative path for project",
|
|
||||||
args: []string{"github.com/spf13/testproject"},
|
|
||||||
pkgName: "github.com/spf13/testproject",
|
|
||||||
expectErr: true,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
|
|
||||||
assertNoErr(t, initCmd.Flags().Set("pkg-name", tt.pkgName))
|
|
||||||
viper.Set("useViper", true)
|
|
||||||
projectPath, err := initializeProject(tt.args)
|
|
||||||
defer func() {
|
|
||||||
if projectPath != "" {
|
|
||||||
os.RemoveAll(projectPath)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
if !tt.expectErr && err != nil {
|
|
||||||
t.Fatalf("did not expect an error, got %s", err)
|
|
||||||
}
|
|
||||||
if tt.expectErr {
|
|
||||||
if err == nil {
|
|
||||||
t.Fatal("expected an error but got none")
|
|
||||||
} else {
|
|
||||||
// got an expected error nothing more to do
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
expectedFiles := []string{"LICENSE", "main.go", "cmd/root.go"}
|
|
||||||
for _, f := range expectedFiles {
|
|
||||||
generatedFile := fmt.Sprintf("%s/%s", projectPath, f)
|
|
||||||
goldenFile := fmt.Sprintf("testdata/%s.golden", filepath.Base(f))
|
|
||||||
err := compareFiles(generatedFile, goldenFile)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,683 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initAgpl() {
|
|
||||||
Licenses["agpl"] = License{
|
|
||||||
Name: "GNU Affero General Public License",
|
|
||||||
PossibleMatches: []string{"agpl", "affero gpl", "gnu agpl"},
|
|
||||||
Header: `
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.`,
|
|
||||||
Text: ` GNU AFFERO GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 19 November 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU Affero General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works, specifically designed to ensure
|
|
||||||
cooperation with the community in the case of network server software.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
our General Public Licenses are intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
Developers that use our General Public Licenses protect your rights
|
|
||||||
with two steps: (1) assert copyright on the software, and (2) offer
|
|
||||||
you this License which gives you legal permission to copy, distribute
|
|
||||||
and/or modify the software.
|
|
||||||
|
|
||||||
A secondary benefit of defending all users' freedom is that
|
|
||||||
improvements made in alternate versions of the program, if they
|
|
||||||
receive widespread use, become available for other developers to
|
|
||||||
incorporate. Many developers of free software are heartened and
|
|
||||||
encouraged by the resulting cooperation. However, in the case of
|
|
||||||
software used on network servers, this result may fail to come about.
|
|
||||||
The GNU General Public License permits making a modified version and
|
|
||||||
letting the public access it on a server without ever releasing its
|
|
||||||
source code to the public.
|
|
||||||
|
|
||||||
The GNU Affero General Public License is designed specifically to
|
|
||||||
ensure that, in such cases, the modified source code becomes available
|
|
||||||
to the community. It requires the operator of a network server to
|
|
||||||
provide the source code of the modified version running there to the
|
|
||||||
users of that server. Therefore, public use of a modified version, on
|
|
||||||
a publicly accessible server, gives the public access to the source
|
|
||||||
code of the modified version.
|
|
||||||
|
|
||||||
An older license, called the Affero General Public License and
|
|
||||||
published by Affero, was designed to accomplish similar goals. This is
|
|
||||||
a different license, not a version of the Affero GPL, but Affero has
|
|
||||||
released a new version of the Affero GPL which permits relicensing under
|
|
||||||
this license.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, if you modify the
|
|
||||||
Program, your modified version must prominently offer all users
|
|
||||||
interacting with it remotely through a computer network (if your version
|
|
||||||
supports such interaction) an opportunity to receive the Corresponding
|
|
||||||
Source of your version by providing access to the Corresponding Source
|
|
||||||
from a network server at no charge, through some standard or customary
|
|
||||||
means of facilitating copying of software. This Corresponding Source
|
|
||||||
shall include the Corresponding Source for any work covered by version 3
|
|
||||||
of the GNU General Public License that is incorporated pursuant to the
|
|
||||||
following paragraph.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the work with which it is combined will remain governed by version
|
|
||||||
3 of the GNU General Public License.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU Affero General Public License from time to time. Such new versions
|
|
||||||
will be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU Affero General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU Affero General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU Affero General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Affero General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Affero General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Affero General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If your software can interact with users remotely through a computer
|
|
||||||
network, you should also make sure that it provides a way for users to
|
|
||||||
get its source. For example, if your program is a web application, its
|
|
||||||
interface could display a "Source" link that leads users to an archive
|
|
||||||
of the code. There are many ways you could offer source, and different
|
|
||||||
solutions will be better for different programs; see section 13 for the
|
|
||||||
specific requirements.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,238 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initApache2() {
|
|
||||||
Licenses["apache"] = License{
|
|
||||||
Name: "Apache 2.0",
|
|
||||||
PossibleMatches: []string{"apache", "apache20", "apache 2.0", "apache2.0", "apache-2.0"},
|
|
||||||
Header: `
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.`,
|
|
||||||
Text: `
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initBsdClause2() {
|
|
||||||
Licenses["freebsd"] = License{
|
|
||||||
Name: "Simplified BSD License",
|
|
||||||
PossibleMatches: []string{"freebsd", "simpbsd", "simple bsd", "2-clause bsd",
|
|
||||||
"2 clause bsd", "simplified bsd license"},
|
|
||||||
Header: `All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.`,
|
|
||||||
Text: `{{ .copyright }}
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initBsdClause3() {
|
|
||||||
Licenses["bsd"] = License{
|
|
||||||
Name: "NewBSD",
|
|
||||||
PossibleMatches: []string{"bsd", "newbsd", "3 clause bsd", "3-clause bsd"},
|
|
||||||
Header: `All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software
|
|
||||||
without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
||||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
||||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
||||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
||||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
||||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
||||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGE.`,
|
|
||||||
Text: `{{ .copyright }}
|
|
||||||
All rights reserved.
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are met:
|
|
||||||
|
|
||||||
1. Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer in the documentation
|
|
||||||
and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
3. Neither the name of the copyright holder nor the names of its contributors
|
|
||||||
may be used to endorse or promote products derived from this software
|
|
||||||
without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
||||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
||||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
||||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
||||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
||||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
||||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
||||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
||||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,376 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initGpl2() {
|
|
||||||
Licenses["gpl2"] = License{
|
|
||||||
Name: "GNU General Public License 2.0",
|
|
||||||
PossibleMatches: []string{"gpl2", "gnu gpl2", "gplv2"},
|
|
||||||
Header: `
|
|
||||||
This program is free software; you can redistribute it and/or
|
|
||||||
modify it under the terms of the GNU General Public License
|
|
||||||
as published by the Free Software Foundation; either version 2
|
|
||||||
of the License, or (at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.`,
|
|
||||||
Text: ` GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 2, June 1991
|
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The licenses for most software are designed to take away your
|
|
||||||
freedom to share and change it. By contrast, the GNU General Public
|
|
||||||
License is intended to guarantee your freedom to share and change free
|
|
||||||
software--to make sure the software is free for all its users. This
|
|
||||||
General Public License applies to most of the Free Software
|
|
||||||
Foundation's software and to any other program whose authors commit to
|
|
||||||
using it. (Some other Free Software Foundation software is covered by
|
|
||||||
the GNU Lesser General Public License instead.) You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
this service if you wish), that you receive source code or can get it
|
|
||||||
if you want it, that you can change the software or use pieces of it
|
|
||||||
in new free programs; and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to make restrictions that forbid
|
|
||||||
anyone to deny you these rights or to ask you to surrender the rights.
|
|
||||||
These restrictions translate to certain responsibilities for you if you
|
|
||||||
distribute copies of the software, or if you modify it.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must give the recipients all the rights that
|
|
||||||
you have. You must make sure that they, too, receive or can get the
|
|
||||||
source code. And you must show them these terms so they know their
|
|
||||||
rights.
|
|
||||||
|
|
||||||
We protect your rights with two steps: (1) copyright the software, and
|
|
||||||
(2) offer you this license which gives you legal permission to copy,
|
|
||||||
distribute and/or modify the software.
|
|
||||||
|
|
||||||
Also, for each author's protection and ours, we want to make certain
|
|
||||||
that everyone understands that there is no warranty for this free
|
|
||||||
software. If the software is modified by someone else and passed on, we
|
|
||||||
want its recipients to know that what they have is not the original, so
|
|
||||||
that any problems introduced by others will not reflect on the original
|
|
||||||
authors' reputations.
|
|
||||||
|
|
||||||
Finally, any free program is threatened constantly by software
|
|
||||||
patents. We wish to avoid the danger that redistributors of a free
|
|
||||||
program will individually obtain patent licenses, in effect making the
|
|
||||||
program proprietary. To prevent this, we have made it clear that any
|
|
||||||
patent must be licensed for everyone's free use or not licensed at all.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
GNU GENERAL PUBLIC LICENSE
|
|
||||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
|
||||||
|
|
||||||
0. This License applies to any program or other work which contains
|
|
||||||
a notice placed by the copyright holder saying it may be distributed
|
|
||||||
under the terms of this General Public License. The "Program", below,
|
|
||||||
refers to any such program or work, and a "work based on the Program"
|
|
||||||
means either the Program or any derivative work under copyright law:
|
|
||||||
that is to say, a work containing the Program or a portion of it,
|
|
||||||
either verbatim or with modifications and/or translated into another
|
|
||||||
language. (Hereinafter, translation is included without limitation in
|
|
||||||
the term "modification".) Each licensee is addressed as "you".
|
|
||||||
|
|
||||||
Activities other than copying, distribution and modification are not
|
|
||||||
covered by this License; they are outside its scope. The act of
|
|
||||||
running the Program is not restricted, and the output from the Program
|
|
||||||
is covered only if its contents constitute a work based on the
|
|
||||||
Program (independent of having been made by running the Program).
|
|
||||||
Whether that is true depends on what the Program does.
|
|
||||||
|
|
||||||
1. You may copy and distribute verbatim copies of the Program's
|
|
||||||
source code as you receive it, in any medium, provided that you
|
|
||||||
conspicuously and appropriately publish on each copy an appropriate
|
|
||||||
copyright notice and disclaimer of warranty; keep intact all the
|
|
||||||
notices that refer to this License and to the absence of any warranty;
|
|
||||||
and give any other recipients of the Program a copy of this License
|
|
||||||
along with the Program.
|
|
||||||
|
|
||||||
You may charge a fee for the physical act of transferring a copy, and
|
|
||||||
you may at your option offer warranty protection in exchange for a fee.
|
|
||||||
|
|
||||||
2. You may modify your copy or copies of the Program or any portion
|
|
||||||
of it, thus forming a work based on the Program, and copy and
|
|
||||||
distribute such modifications or work under the terms of Section 1
|
|
||||||
above, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) You must cause the modified files to carry prominent notices
|
|
||||||
stating that you changed the files and the date of any change.
|
|
||||||
|
|
||||||
b) You must cause any work that you distribute or publish, that in
|
|
||||||
whole or in part contains or is derived from the Program or any
|
|
||||||
part thereof, to be licensed as a whole at no charge to all third
|
|
||||||
parties under the terms of this License.
|
|
||||||
|
|
||||||
c) If the modified program normally reads commands interactively
|
|
||||||
when run, you must cause it, when started running for such
|
|
||||||
interactive use in the most ordinary way, to print or display an
|
|
||||||
announcement including an appropriate copyright notice and a
|
|
||||||
notice that there is no warranty (or else, saying that you provide
|
|
||||||
a warranty) and that users may redistribute the program under
|
|
||||||
these conditions, and telling the user how to view a copy of this
|
|
||||||
License. (Exception: if the Program itself is interactive but
|
|
||||||
does not normally print such an announcement, your work based on
|
|
||||||
the Program is not required to print an announcement.)
|
|
||||||
|
|
||||||
These requirements apply to the modified work as a whole. If
|
|
||||||
identifiable sections of that work are not derived from the Program,
|
|
||||||
and can be reasonably considered independent and separate works in
|
|
||||||
themselves, then this License, and its terms, do not apply to those
|
|
||||||
sections when you distribute them as separate works. But when you
|
|
||||||
distribute the same sections as part of a whole which is a work based
|
|
||||||
on the Program, the distribution of the whole must be on the terms of
|
|
||||||
this License, whose permissions for other licensees extend to the
|
|
||||||
entire whole, and thus to each and every part regardless of who wrote it.
|
|
||||||
|
|
||||||
Thus, it is not the intent of this section to claim rights or contest
|
|
||||||
your rights to work written entirely by you; rather, the intent is to
|
|
||||||
exercise the right to control the distribution of derivative or
|
|
||||||
collective works based on the Program.
|
|
||||||
|
|
||||||
In addition, mere aggregation of another work not based on the Program
|
|
||||||
with the Program (or with a work based on the Program) on a volume of
|
|
||||||
a storage or distribution medium does not bring the other work under
|
|
||||||
the scope of this License.
|
|
||||||
|
|
||||||
3. You may copy and distribute the Program (or a work based on it,
|
|
||||||
under Section 2) in object code or executable form under the terms of
|
|
||||||
Sections 1 and 2 above provided that you also do one of the following:
|
|
||||||
|
|
||||||
a) Accompany it with the complete corresponding machine-readable
|
|
||||||
source code, which must be distributed under the terms of Sections
|
|
||||||
1 and 2 above on a medium customarily used for software interchange; or,
|
|
||||||
|
|
||||||
b) Accompany it with a written offer, valid for at least three
|
|
||||||
years, to give any third party, for a charge no more than your
|
|
||||||
cost of physically performing source distribution, a complete
|
|
||||||
machine-readable copy of the corresponding source code, to be
|
|
||||||
distributed under the terms of Sections 1 and 2 above on a medium
|
|
||||||
customarily used for software interchange; or,
|
|
||||||
|
|
||||||
c) Accompany it with the information you received as to the offer
|
|
||||||
to distribute corresponding source code. (This alternative is
|
|
||||||
allowed only for noncommercial distribution and only if you
|
|
||||||
received the program in object code or executable form with such
|
|
||||||
an offer, in accord with Subsection b above.)
|
|
||||||
|
|
||||||
The source code for a work means the preferred form of the work for
|
|
||||||
making modifications to it. For an executable work, complete source
|
|
||||||
code means all the source code for all modules it contains, plus any
|
|
||||||
associated interface definition files, plus the scripts used to
|
|
||||||
control compilation and installation of the executable. However, as a
|
|
||||||
special exception, the source code distributed need not include
|
|
||||||
anything that is normally distributed (in either source or binary
|
|
||||||
form) with the major components (compiler, kernel, and so on) of the
|
|
||||||
operating system on which the executable runs, unless that component
|
|
||||||
itself accompanies the executable.
|
|
||||||
|
|
||||||
If distribution of executable or object code is made by offering
|
|
||||||
access to copy from a designated place, then offering equivalent
|
|
||||||
access to copy the source code from the same place counts as
|
|
||||||
distribution of the source code, even though third parties are not
|
|
||||||
compelled to copy the source along with the object code.
|
|
||||||
|
|
||||||
4. You may not copy, modify, sublicense, or distribute the Program
|
|
||||||
except as expressly provided under this License. Any attempt
|
|
||||||
otherwise to copy, modify, sublicense or distribute the Program is
|
|
||||||
void, and will automatically terminate your rights under this License.
|
|
||||||
However, parties who have received copies, or rights, from you under
|
|
||||||
this License will not have their licenses terminated so long as such
|
|
||||||
parties remain in full compliance.
|
|
||||||
|
|
||||||
5. You are not required to accept this License, since you have not
|
|
||||||
signed it. However, nothing else grants you permission to modify or
|
|
||||||
distribute the Program or its derivative works. These actions are
|
|
||||||
prohibited by law if you do not accept this License. Therefore, by
|
|
||||||
modifying or distributing the Program (or any work based on the
|
|
||||||
Program), you indicate your acceptance of this License to do so, and
|
|
||||||
all its terms and conditions for copying, distributing or modifying
|
|
||||||
the Program or works based on it.
|
|
||||||
|
|
||||||
6. Each time you redistribute the Program (or any work based on the
|
|
||||||
Program), the recipient automatically receives a license from the
|
|
||||||
original licensor to copy, distribute or modify the Program subject to
|
|
||||||
these terms and conditions. You may not impose any further
|
|
||||||
restrictions on the recipients' exercise of the rights granted herein.
|
|
||||||
You are not responsible for enforcing compliance by third parties to
|
|
||||||
this License.
|
|
||||||
|
|
||||||
7. If, as a consequence of a court judgment or allegation of patent
|
|
||||||
infringement or for any other reason (not limited to patent issues),
|
|
||||||
conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot
|
|
||||||
distribute so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you
|
|
||||||
may not distribute the Program at all. For example, if a patent
|
|
||||||
license would not permit royalty-free redistribution of the Program by
|
|
||||||
all those who receive copies directly or indirectly through you, then
|
|
||||||
the only way you could satisfy both it and this License would be to
|
|
||||||
refrain entirely from distribution of the Program.
|
|
||||||
|
|
||||||
If any portion of this section is held invalid or unenforceable under
|
|
||||||
any particular circumstance, the balance of the section is intended to
|
|
||||||
apply and the section as a whole is intended to apply in other
|
|
||||||
circumstances.
|
|
||||||
|
|
||||||
It is not the purpose of this section to induce you to infringe any
|
|
||||||
patents or other property right claims or to contest validity of any
|
|
||||||
such claims; this section has the sole purpose of protecting the
|
|
||||||
integrity of the free software distribution system, which is
|
|
||||||
implemented by public license practices. Many people have made
|
|
||||||
generous contributions to the wide range of software distributed
|
|
||||||
through that system in reliance on consistent application of that
|
|
||||||
system; it is up to the author/donor to decide if he or she is willing
|
|
||||||
to distribute software through any other system and a licensee cannot
|
|
||||||
impose that choice.
|
|
||||||
|
|
||||||
This section is intended to make thoroughly clear what is believed to
|
|
||||||
be a consequence of the rest of this License.
|
|
||||||
|
|
||||||
8. If the distribution and/or use of the Program is restricted in
|
|
||||||
certain countries either by patents or by copyrighted interfaces, the
|
|
||||||
original copyright holder who places the Program under this License
|
|
||||||
may add an explicit geographical distribution limitation excluding
|
|
||||||
those countries, so that distribution is permitted only in or among
|
|
||||||
countries not thus excluded. In such case, this License incorporates
|
|
||||||
the limitation as if written in the body of this License.
|
|
||||||
|
|
||||||
9. The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the Program
|
|
||||||
specifies a version number of this License which applies to it and "any
|
|
||||||
later version", you have the option of following the terms and conditions
|
|
||||||
either of that version or of any later version published by the Free
|
|
||||||
Software Foundation. If the Program does not specify a version number of
|
|
||||||
this License, you may choose any version ever published by the Free Software
|
|
||||||
Foundation.
|
|
||||||
|
|
||||||
10. If you wish to incorporate parts of the Program into other free
|
|
||||||
programs whose distribution conditions are different, write to the author
|
|
||||||
to ask for permission. For software which is copyrighted by the Free
|
|
||||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
|
||||||
make exceptions for this. Our decision will be guided by the two goals
|
|
||||||
of preserving the free status of all derivatives of our free software and
|
|
||||||
of promoting the sharing and reuse of software generally.
|
|
||||||
|
|
||||||
NO WARRANTY
|
|
||||||
|
|
||||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
|
||||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
|
||||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
|
||||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
|
||||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
|
||||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
|
||||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
|
||||||
REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
|
||||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
|
||||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
|
||||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
|
||||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
|
||||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
|
||||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
|
||||||
POSSIBILITY OF SUCH DAMAGES.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
convey the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation; either version 2 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License along
|
|
||||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program is interactive, make it output a short notice like this
|
|
||||||
when it starts in an interactive mode:
|
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type 'show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands 'show w' and 'show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, the commands you use may
|
|
||||||
be called something other than 'show w' and 'show c'; they could even be
|
|
||||||
mouse-clicks or menu items--whatever suits your program.
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or your
|
|
||||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
|
||||||
necessary. Here is a sample; alter the names:
|
|
||||||
|
|
||||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
|
||||||
'Gnomovision' (which makes passes at compilers) written by James Hacker.
|
|
||||||
|
|
||||||
<signature of Ty Coon>, 1 April 1989
|
|
||||||
Ty Coon, President of Vice
|
|
||||||
|
|
||||||
This General Public License does not permit incorporating your program into
|
|
||||||
proprietary programs. If your program is a subroutine library, you may
|
|
||||||
consider it more useful to permit linking proprietary applications with the
|
|
||||||
library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,711 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initGpl3() {
|
|
||||||
Licenses["gpl3"] = License{
|
|
||||||
Name: "GNU General Public License 3.0",
|
|
||||||
PossibleMatches: []string{"gpl3", "gplv3", "gpl", "gnu gpl3", "gnu gpl"},
|
|
||||||
Header: `
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.`,
|
|
||||||
Text: ` GNU GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
Preamble
|
|
||||||
|
|
||||||
The GNU General Public License is a free, copyleft license for
|
|
||||||
software and other kinds of works.
|
|
||||||
|
|
||||||
The licenses for most software and other practical works are designed
|
|
||||||
to take away your freedom to share and change the works. By contrast,
|
|
||||||
the GNU General Public License is intended to guarantee your freedom to
|
|
||||||
share and change all versions of a program--to make sure it remains free
|
|
||||||
software for all its users. We, the Free Software Foundation, use the
|
|
||||||
GNU General Public License for most of our software; it applies also to
|
|
||||||
any other work released this way by its authors. You can apply it to
|
|
||||||
your programs, too.
|
|
||||||
|
|
||||||
When we speak of free software, we are referring to freedom, not
|
|
||||||
price. Our General Public Licenses are designed to make sure that you
|
|
||||||
have the freedom to distribute copies of free software (and charge for
|
|
||||||
them if you wish), that you receive source code or can get it if you
|
|
||||||
want it, that you can change the software or use pieces of it in new
|
|
||||||
free programs, and that you know you can do these things.
|
|
||||||
|
|
||||||
To protect your rights, we need to prevent others from denying you
|
|
||||||
these rights or asking you to surrender the rights. Therefore, you have
|
|
||||||
certain responsibilities if you distribute copies of the software, or if
|
|
||||||
you modify it: responsibilities to respect the freedom of others.
|
|
||||||
|
|
||||||
For example, if you distribute copies of such a program, whether
|
|
||||||
gratis or for a fee, you must pass on to the recipients the same
|
|
||||||
freedoms that you received. You must make sure that they, too, receive
|
|
||||||
or can get the source code. And you must show them these terms so they
|
|
||||||
know their rights.
|
|
||||||
|
|
||||||
Developers that use the GNU GPL protect your rights with two steps:
|
|
||||||
(1) assert copyright on the software, and (2) offer you this License
|
|
||||||
giving you legal permission to copy, distribute and/or modify it.
|
|
||||||
|
|
||||||
For the developers' and authors' protection, the GPL clearly explains
|
|
||||||
that there is no warranty for this free software. For both users' and
|
|
||||||
authors' sake, the GPL requires that modified versions be marked as
|
|
||||||
changed, so that their problems will not be attributed erroneously to
|
|
||||||
authors of previous versions.
|
|
||||||
|
|
||||||
Some devices are designed to deny users access to install or run
|
|
||||||
modified versions of the software inside them, although the manufacturer
|
|
||||||
can do so. This is fundamentally incompatible with the aim of
|
|
||||||
protecting users' freedom to change the software. The systematic
|
|
||||||
pattern of such abuse occurs in the area of products for individuals to
|
|
||||||
use, which is precisely where it is most unacceptable. Therefore, we
|
|
||||||
have designed this version of the GPL to prohibit the practice for those
|
|
||||||
products. If such problems arise substantially in other domains, we
|
|
||||||
stand ready to extend this provision to those domains in future versions
|
|
||||||
of the GPL, as needed to protect the freedom of users.
|
|
||||||
|
|
||||||
Finally, every program is threatened constantly by software patents.
|
|
||||||
States should not allow patents to restrict development and use of
|
|
||||||
software on general-purpose computers, but in those that do, we wish to
|
|
||||||
avoid the special danger that patents applied to a free program could
|
|
||||||
make it effectively proprietary. To prevent this, the GPL assures that
|
|
||||||
patents cannot be used to render the program non-free.
|
|
||||||
|
|
||||||
The precise terms and conditions for copying, distribution and
|
|
||||||
modification follow.
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
0. Definitions.
|
|
||||||
|
|
||||||
"This License" refers to version 3 of the GNU General Public License.
|
|
||||||
|
|
||||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
|
||||||
works, such as semiconductor masks.
|
|
||||||
|
|
||||||
"The Program" refers to any copyrightable work licensed under this
|
|
||||||
License. Each licensee is addressed as "you". "Licensees" and
|
|
||||||
"recipients" may be individuals or organizations.
|
|
||||||
|
|
||||||
To "modify" a work means to copy from or adapt all or part of the work
|
|
||||||
in a fashion requiring copyright permission, other than the making of an
|
|
||||||
exact copy. The resulting work is called a "modified version" of the
|
|
||||||
earlier work or a work "based on" the earlier work.
|
|
||||||
|
|
||||||
A "covered work" means either the unmodified Program or a work based
|
|
||||||
on the Program.
|
|
||||||
|
|
||||||
To "propagate" a work means to do anything with it that, without
|
|
||||||
permission, would make you directly or secondarily liable for
|
|
||||||
infringement under applicable copyright law, except executing it on a
|
|
||||||
computer or modifying a private copy. Propagation includes copying,
|
|
||||||
distribution (with or without modification), making available to the
|
|
||||||
public, and in some countries other activities as well.
|
|
||||||
|
|
||||||
To "convey" a work means any kind of propagation that enables other
|
|
||||||
parties to make or receive copies. Mere interaction with a user through
|
|
||||||
a computer network, with no transfer of a copy, is not conveying.
|
|
||||||
|
|
||||||
An interactive user interface displays "Appropriate Legal Notices"
|
|
||||||
to the extent that it includes a convenient and prominently visible
|
|
||||||
feature that (1) displays an appropriate copyright notice, and (2)
|
|
||||||
tells the user that there is no warranty for the work (except to the
|
|
||||||
extent that warranties are provided), that licensees may convey the
|
|
||||||
work under this License, and how to view a copy of this License. If
|
|
||||||
the interface presents a list of user commands or options, such as a
|
|
||||||
menu, a prominent item in the list meets this criterion.
|
|
||||||
|
|
||||||
1. Source Code.
|
|
||||||
|
|
||||||
The "source code" for a work means the preferred form of the work
|
|
||||||
for making modifications to it. "Object code" means any non-source
|
|
||||||
form of a work.
|
|
||||||
|
|
||||||
A "Standard Interface" means an interface that either is an official
|
|
||||||
standard defined by a recognized standards body, or, in the case of
|
|
||||||
interfaces specified for a particular programming language, one that
|
|
||||||
is widely used among developers working in that language.
|
|
||||||
|
|
||||||
The "System Libraries" of an executable work include anything, other
|
|
||||||
than the work as a whole, that (a) is included in the normal form of
|
|
||||||
packaging a Major Component, but which is not part of that Major
|
|
||||||
Component, and (b) serves only to enable use of the work with that
|
|
||||||
Major Component, or to implement a Standard Interface for which an
|
|
||||||
implementation is available to the public in source code form. A
|
|
||||||
"Major Component", in this context, means a major essential component
|
|
||||||
(kernel, window system, and so on) of the specific operating system
|
|
||||||
(if any) on which the executable work runs, or a compiler used to
|
|
||||||
produce the work, or an object code interpreter used to run it.
|
|
||||||
|
|
||||||
The "Corresponding Source" for a work in object code form means all
|
|
||||||
the source code needed to generate, install, and (for an executable
|
|
||||||
work) run the object code and to modify the work, including scripts to
|
|
||||||
control those activities. However, it does not include the work's
|
|
||||||
System Libraries, or general-purpose tools or generally available free
|
|
||||||
programs which are used unmodified in performing those activities but
|
|
||||||
which are not part of the work. For example, Corresponding Source
|
|
||||||
includes interface definition files associated with source files for
|
|
||||||
the work, and the source code for shared libraries and dynamically
|
|
||||||
linked subprograms that the work is specifically designed to require,
|
|
||||||
such as by intimate data communication or control flow between those
|
|
||||||
subprograms and other parts of the work.
|
|
||||||
|
|
||||||
The Corresponding Source need not include anything that users
|
|
||||||
can regenerate automatically from other parts of the Corresponding
|
|
||||||
Source.
|
|
||||||
|
|
||||||
The Corresponding Source for a work in source code form is that
|
|
||||||
same work.
|
|
||||||
|
|
||||||
2. Basic Permissions.
|
|
||||||
|
|
||||||
All rights granted under this License are granted for the term of
|
|
||||||
copyright on the Program, and are irrevocable provided the stated
|
|
||||||
conditions are met. This License explicitly affirms your unlimited
|
|
||||||
permission to run the unmodified Program. The output from running a
|
|
||||||
covered work is covered by this License only if the output, given its
|
|
||||||
content, constitutes a covered work. This License acknowledges your
|
|
||||||
rights of fair use or other equivalent, as provided by copyright law.
|
|
||||||
|
|
||||||
You may make, run and propagate covered works that you do not
|
|
||||||
convey, without conditions so long as your license otherwise remains
|
|
||||||
in force. You may convey covered works to others for the sole purpose
|
|
||||||
of having them make modifications exclusively for you, or provide you
|
|
||||||
with facilities for running those works, provided that you comply with
|
|
||||||
the terms of this License in conveying all material for which you do
|
|
||||||
not control copyright. Those thus making or running the covered works
|
|
||||||
for you must do so exclusively on your behalf, under your direction
|
|
||||||
and control, on terms that prohibit them from making any copies of
|
|
||||||
your copyrighted material outside their relationship with you.
|
|
||||||
|
|
||||||
Conveying under any other circumstances is permitted solely under
|
|
||||||
the conditions stated below. Sublicensing is not allowed; section 10
|
|
||||||
makes it unnecessary.
|
|
||||||
|
|
||||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
|
||||||
|
|
||||||
No covered work shall be deemed part of an effective technological
|
|
||||||
measure under any applicable law fulfilling obligations under article
|
|
||||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
|
||||||
similar laws prohibiting or restricting circumvention of such
|
|
||||||
measures.
|
|
||||||
|
|
||||||
When you convey a covered work, you waive any legal power to forbid
|
|
||||||
circumvention of technological measures to the extent such circumvention
|
|
||||||
is effected by exercising rights under this License with respect to
|
|
||||||
the covered work, and you disclaim any intention to limit operation or
|
|
||||||
modification of the work as a means of enforcing, against the work's
|
|
||||||
users, your or third parties' legal rights to forbid circumvention of
|
|
||||||
technological measures.
|
|
||||||
|
|
||||||
4. Conveying Verbatim Copies.
|
|
||||||
|
|
||||||
You may convey verbatim copies of the Program's source code as you
|
|
||||||
receive it, in any medium, provided that you conspicuously and
|
|
||||||
appropriately publish on each copy an appropriate copyright notice;
|
|
||||||
keep intact all notices stating that this License and any
|
|
||||||
non-permissive terms added in accord with section 7 apply to the code;
|
|
||||||
keep intact all notices of the absence of any warranty; and give all
|
|
||||||
recipients a copy of this License along with the Program.
|
|
||||||
|
|
||||||
You may charge any price or no price for each copy that you convey,
|
|
||||||
and you may offer support or warranty protection for a fee.
|
|
||||||
|
|
||||||
5. Conveying Modified Source Versions.
|
|
||||||
|
|
||||||
You may convey a work based on the Program, or the modifications to
|
|
||||||
produce it from the Program, in the form of source code under the
|
|
||||||
terms of section 4, provided that you also meet all of these conditions:
|
|
||||||
|
|
||||||
a) The work must carry prominent notices stating that you modified
|
|
||||||
it, and giving a relevant date.
|
|
||||||
|
|
||||||
b) The work must carry prominent notices stating that it is
|
|
||||||
released under this License and any conditions added under section
|
|
||||||
7. This requirement modifies the requirement in section 4 to
|
|
||||||
"keep intact all notices".
|
|
||||||
|
|
||||||
c) You must license the entire work, as a whole, under this
|
|
||||||
License to anyone who comes into possession of a copy. This
|
|
||||||
License will therefore apply, along with any applicable section 7
|
|
||||||
additional terms, to the whole of the work, and all its parts,
|
|
||||||
regardless of how they are packaged. This License gives no
|
|
||||||
permission to license the work in any other way, but it does not
|
|
||||||
invalidate such permission if you have separately received it.
|
|
||||||
|
|
||||||
d) If the work has interactive user interfaces, each must display
|
|
||||||
Appropriate Legal Notices; however, if the Program has interactive
|
|
||||||
interfaces that do not display Appropriate Legal Notices, your
|
|
||||||
work need not make them do so.
|
|
||||||
|
|
||||||
A compilation of a covered work with other separate and independent
|
|
||||||
works, which are not by their nature extensions of the covered work,
|
|
||||||
and which are not combined with it such as to form a larger program,
|
|
||||||
in or on a volume of a storage or distribution medium, is called an
|
|
||||||
"aggregate" if the compilation and its resulting copyright are not
|
|
||||||
used to limit the access or legal rights of the compilation's users
|
|
||||||
beyond what the individual works permit. Inclusion of a covered work
|
|
||||||
in an aggregate does not cause this License to apply to the other
|
|
||||||
parts of the aggregate.
|
|
||||||
|
|
||||||
6. Conveying Non-Source Forms.
|
|
||||||
|
|
||||||
You may convey a covered work in object code form under the terms
|
|
||||||
of sections 4 and 5, provided that you also convey the
|
|
||||||
machine-readable Corresponding Source under the terms of this License,
|
|
||||||
in one of these ways:
|
|
||||||
|
|
||||||
a) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by the
|
|
||||||
Corresponding Source fixed on a durable physical medium
|
|
||||||
customarily used for software interchange.
|
|
||||||
|
|
||||||
b) Convey the object code in, or embodied in, a physical product
|
|
||||||
(including a physical distribution medium), accompanied by a
|
|
||||||
written offer, valid for at least three years and valid for as
|
|
||||||
long as you offer spare parts or customer support for that product
|
|
||||||
model, to give anyone who possesses the object code either (1) a
|
|
||||||
copy of the Corresponding Source for all the software in the
|
|
||||||
product that is covered by this License, on a durable physical
|
|
||||||
medium customarily used for software interchange, for a price no
|
|
||||||
more than your reasonable cost of physically performing this
|
|
||||||
conveying of source, or (2) access to copy the
|
|
||||||
Corresponding Source from a network server at no charge.
|
|
||||||
|
|
||||||
c) Convey individual copies of the object code with a copy of the
|
|
||||||
written offer to provide the Corresponding Source. This
|
|
||||||
alternative is allowed only occasionally and noncommercially, and
|
|
||||||
only if you received the object code with such an offer, in accord
|
|
||||||
with subsection 6b.
|
|
||||||
|
|
||||||
d) Convey the object code by offering access from a designated
|
|
||||||
place (gratis or for a charge), and offer equivalent access to the
|
|
||||||
Corresponding Source in the same way through the same place at no
|
|
||||||
further charge. You need not require recipients to copy the
|
|
||||||
Corresponding Source along with the object code. If the place to
|
|
||||||
copy the object code is a network server, the Corresponding Source
|
|
||||||
may be on a different server (operated by you or a third party)
|
|
||||||
that supports equivalent copying facilities, provided you maintain
|
|
||||||
clear directions next to the object code saying where to find the
|
|
||||||
Corresponding Source. Regardless of what server hosts the
|
|
||||||
Corresponding Source, you remain obligated to ensure that it is
|
|
||||||
available for as long as needed to satisfy these requirements.
|
|
||||||
|
|
||||||
e) Convey the object code using peer-to-peer transmission, provided
|
|
||||||
you inform other peers where the object code and Corresponding
|
|
||||||
Source of the work are being offered to the general public at no
|
|
||||||
charge under subsection 6d.
|
|
||||||
|
|
||||||
A separable portion of the object code, whose source code is excluded
|
|
||||||
from the Corresponding Source as a System Library, need not be
|
|
||||||
included in conveying the object code work.
|
|
||||||
|
|
||||||
A "User Product" is either (1) a "consumer product", which means any
|
|
||||||
tangible personal property which is normally used for personal, family,
|
|
||||||
or household purposes, or (2) anything designed or sold for incorporation
|
|
||||||
into a dwelling. In determining whether a product is a consumer product,
|
|
||||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
|
||||||
product received by a particular user, "normally used" refers to a
|
|
||||||
typical or common use of that class of product, regardless of the status
|
|
||||||
of the particular user or of the way in which the particular user
|
|
||||||
actually uses, or expects or is expected to use, the product. A product
|
|
||||||
is a consumer product regardless of whether the product has substantial
|
|
||||||
commercial, industrial or non-consumer uses, unless such uses represent
|
|
||||||
the only significant mode of use of the product.
|
|
||||||
|
|
||||||
"Installation Information" for a User Product means any methods,
|
|
||||||
procedures, authorization keys, or other information required to install
|
|
||||||
and execute modified versions of a covered work in that User Product from
|
|
||||||
a modified version of its Corresponding Source. The information must
|
|
||||||
suffice to ensure that the continued functioning of the modified object
|
|
||||||
code is in no case prevented or interfered with solely because
|
|
||||||
modification has been made.
|
|
||||||
|
|
||||||
If you convey an object code work under this section in, or with, or
|
|
||||||
specifically for use in, a User Product, and the conveying occurs as
|
|
||||||
part of a transaction in which the right of possession and use of the
|
|
||||||
User Product is transferred to the recipient in perpetuity or for a
|
|
||||||
fixed term (regardless of how the transaction is characterized), the
|
|
||||||
Corresponding Source conveyed under this section must be accompanied
|
|
||||||
by the Installation Information. But this requirement does not apply
|
|
||||||
if neither you nor any third party retains the ability to install
|
|
||||||
modified object code on the User Product (for example, the work has
|
|
||||||
been installed in ROM).
|
|
||||||
|
|
||||||
The requirement to provide Installation Information does not include a
|
|
||||||
requirement to continue to provide support service, warranty, or updates
|
|
||||||
for a work that has been modified or installed by the recipient, or for
|
|
||||||
the User Product in which it has been modified or installed. Access to a
|
|
||||||
network may be denied when the modification itself materially and
|
|
||||||
adversely affects the operation of the network or violates the rules and
|
|
||||||
protocols for communication across the network.
|
|
||||||
|
|
||||||
Corresponding Source conveyed, and Installation Information provided,
|
|
||||||
in accord with this section must be in a format that is publicly
|
|
||||||
documented (and with an implementation available to the public in
|
|
||||||
source code form), and must require no special password or key for
|
|
||||||
unpacking, reading or copying.
|
|
||||||
|
|
||||||
7. Additional Terms.
|
|
||||||
|
|
||||||
"Additional permissions" are terms that supplement the terms of this
|
|
||||||
License by making exceptions from one or more of its conditions.
|
|
||||||
Additional permissions that are applicable to the entire Program shall
|
|
||||||
be treated as though they were included in this License, to the extent
|
|
||||||
that they are valid under applicable law. If additional permissions
|
|
||||||
apply only to part of the Program, that part may be used separately
|
|
||||||
under those permissions, but the entire Program remains governed by
|
|
||||||
this License without regard to the additional permissions.
|
|
||||||
|
|
||||||
When you convey a copy of a covered work, you may at your option
|
|
||||||
remove any additional permissions from that copy, or from any part of
|
|
||||||
it. (Additional permissions may be written to require their own
|
|
||||||
removal in certain cases when you modify the work.) You may place
|
|
||||||
additional permissions on material, added by you to a covered work,
|
|
||||||
for which you have or can give appropriate copyright permission.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, for material you
|
|
||||||
add to a covered work, you may (if authorized by the copyright holders of
|
|
||||||
that material) supplement the terms of this License with terms:
|
|
||||||
|
|
||||||
a) Disclaiming warranty or limiting liability differently from the
|
|
||||||
terms of sections 15 and 16 of this License; or
|
|
||||||
|
|
||||||
b) Requiring preservation of specified reasonable legal notices or
|
|
||||||
author attributions in that material or in the Appropriate Legal
|
|
||||||
Notices displayed by works containing it; or
|
|
||||||
|
|
||||||
c) Prohibiting misrepresentation of the origin of that material, or
|
|
||||||
requiring that modified versions of such material be marked in
|
|
||||||
reasonable ways as different from the original version; or
|
|
||||||
|
|
||||||
d) Limiting the use for publicity purposes of names of licensors or
|
|
||||||
authors of the material; or
|
|
||||||
|
|
||||||
e) Declining to grant rights under trademark law for use of some
|
|
||||||
trade names, trademarks, or service marks; or
|
|
||||||
|
|
||||||
f) Requiring indemnification of licensors and authors of that
|
|
||||||
material by anyone who conveys the material (or modified versions of
|
|
||||||
it) with contractual assumptions of liability to the recipient, for
|
|
||||||
any liability that these contractual assumptions directly impose on
|
|
||||||
those licensors and authors.
|
|
||||||
|
|
||||||
All other non-permissive additional terms are considered "further
|
|
||||||
restrictions" within the meaning of section 10. If the Program as you
|
|
||||||
received it, or any part of it, contains a notice stating that it is
|
|
||||||
governed by this License along with a term that is a further
|
|
||||||
restriction, you may remove that term. If a license document contains
|
|
||||||
a further restriction but permits relicensing or conveying under this
|
|
||||||
License, you may add to a covered work material governed by the terms
|
|
||||||
of that license document, provided that the further restriction does
|
|
||||||
not survive such relicensing or conveying.
|
|
||||||
|
|
||||||
If you add terms to a covered work in accord with this section, you
|
|
||||||
must place, in the relevant source files, a statement of the
|
|
||||||
additional terms that apply to those files, or a notice indicating
|
|
||||||
where to find the applicable terms.
|
|
||||||
|
|
||||||
Additional terms, permissive or non-permissive, may be stated in the
|
|
||||||
form of a separately written license, or stated as exceptions;
|
|
||||||
the above requirements apply either way.
|
|
||||||
|
|
||||||
8. Termination.
|
|
||||||
|
|
||||||
You may not propagate or modify a covered work except as expressly
|
|
||||||
provided under this License. Any attempt otherwise to propagate or
|
|
||||||
modify it is void, and will automatically terminate your rights under
|
|
||||||
this License (including any patent licenses granted under the third
|
|
||||||
paragraph of section 11).
|
|
||||||
|
|
||||||
However, if you cease all violation of this License, then your
|
|
||||||
license from a particular copyright holder is reinstated (a)
|
|
||||||
provisionally, unless and until the copyright holder explicitly and
|
|
||||||
finally terminates your license, and (b) permanently, if the copyright
|
|
||||||
holder fails to notify you of the violation by some reasonable means
|
|
||||||
prior to 60 days after the cessation.
|
|
||||||
|
|
||||||
Moreover, your license from a particular copyright holder is
|
|
||||||
reinstated permanently if the copyright holder notifies you of the
|
|
||||||
violation by some reasonable means, this is the first time you have
|
|
||||||
received notice of violation of this License (for any work) from that
|
|
||||||
copyright holder, and you cure the violation prior to 30 days after
|
|
||||||
your receipt of the notice.
|
|
||||||
|
|
||||||
Termination of your rights under this section does not terminate the
|
|
||||||
licenses of parties who have received copies or rights from you under
|
|
||||||
this License. If your rights have been terminated and not permanently
|
|
||||||
reinstated, you do not qualify to receive new licenses for the same
|
|
||||||
material under section 10.
|
|
||||||
|
|
||||||
9. Acceptance Not Required for Having Copies.
|
|
||||||
|
|
||||||
You are not required to accept this License in order to receive or
|
|
||||||
run a copy of the Program. Ancillary propagation of a covered work
|
|
||||||
occurring solely as a consequence of using peer-to-peer transmission
|
|
||||||
to receive a copy likewise does not require acceptance. However,
|
|
||||||
nothing other than this License grants you permission to propagate or
|
|
||||||
modify any covered work. These actions infringe copyright if you do
|
|
||||||
not accept this License. Therefore, by modifying or propagating a
|
|
||||||
covered work, you indicate your acceptance of this License to do so.
|
|
||||||
|
|
||||||
10. Automatic Licensing of Downstream Recipients.
|
|
||||||
|
|
||||||
Each time you convey a covered work, the recipient automatically
|
|
||||||
receives a license from the original licensors, to run, modify and
|
|
||||||
propagate that work, subject to this License. You are not responsible
|
|
||||||
for enforcing compliance by third parties with this License.
|
|
||||||
|
|
||||||
An "entity transaction" is a transaction transferring control of an
|
|
||||||
organization, or substantially all assets of one, or subdividing an
|
|
||||||
organization, or merging organizations. If propagation of a covered
|
|
||||||
work results from an entity transaction, each party to that
|
|
||||||
transaction who receives a copy of the work also receives whatever
|
|
||||||
licenses to the work the party's predecessor in interest had or could
|
|
||||||
give under the previous paragraph, plus a right to possession of the
|
|
||||||
Corresponding Source of the work from the predecessor in interest, if
|
|
||||||
the predecessor has it or can get it with reasonable efforts.
|
|
||||||
|
|
||||||
You may not impose any further restrictions on the exercise of the
|
|
||||||
rights granted or affirmed under this License. For example, you may
|
|
||||||
not impose a license fee, royalty, or other charge for exercise of
|
|
||||||
rights granted under this License, and you may not initiate litigation
|
|
||||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
|
||||||
any patent claim is infringed by making, using, selling, offering for
|
|
||||||
sale, or importing the Program or any portion of it.
|
|
||||||
|
|
||||||
11. Patents.
|
|
||||||
|
|
||||||
A "contributor" is a copyright holder who authorizes use under this
|
|
||||||
License of the Program or a work on which the Program is based. The
|
|
||||||
work thus licensed is called the contributor's "contributor version".
|
|
||||||
|
|
||||||
A contributor's "essential patent claims" are all patent claims
|
|
||||||
owned or controlled by the contributor, whether already acquired or
|
|
||||||
hereafter acquired, that would be infringed by some manner, permitted
|
|
||||||
by this License, of making, using, or selling its contributor version,
|
|
||||||
but do not include claims that would be infringed only as a
|
|
||||||
consequence of further modification of the contributor version. For
|
|
||||||
purposes of this definition, "control" includes the right to grant
|
|
||||||
patent sublicenses in a manner consistent with the requirements of
|
|
||||||
this License.
|
|
||||||
|
|
||||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
|
||||||
patent license under the contributor's essential patent claims, to
|
|
||||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
|
||||||
propagate the contents of its contributor version.
|
|
||||||
|
|
||||||
In the following three paragraphs, a "patent license" is any express
|
|
||||||
agreement or commitment, however denominated, not to enforce a patent
|
|
||||||
(such as an express permission to practice a patent or covenant not to
|
|
||||||
sue for patent infringement). To "grant" such a patent license to a
|
|
||||||
party means to make such an agreement or commitment not to enforce a
|
|
||||||
patent against the party.
|
|
||||||
|
|
||||||
If you convey a covered work, knowingly relying on a patent license,
|
|
||||||
and the Corresponding Source of the work is not available for anyone
|
|
||||||
to copy, free of charge and under the terms of this License, through a
|
|
||||||
publicly available network server or other readily accessible means,
|
|
||||||
then you must either (1) cause the Corresponding Source to be so
|
|
||||||
available, or (2) arrange to deprive yourself of the benefit of the
|
|
||||||
patent license for this particular work, or (3) arrange, in a manner
|
|
||||||
consistent with the requirements of this License, to extend the patent
|
|
||||||
license to downstream recipients. "Knowingly relying" means you have
|
|
||||||
actual knowledge that, but for the patent license, your conveying the
|
|
||||||
covered work in a country, or your recipient's use of the covered work
|
|
||||||
in a country, would infringe one or more identifiable patents in that
|
|
||||||
country that you have reason to believe are valid.
|
|
||||||
|
|
||||||
If, pursuant to or in connection with a single transaction or
|
|
||||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
|
||||||
covered work, and grant a patent license to some of the parties
|
|
||||||
receiving the covered work authorizing them to use, propagate, modify
|
|
||||||
or convey a specific copy of the covered work, then the patent license
|
|
||||||
you grant is automatically extended to all recipients of the covered
|
|
||||||
work and works based on it.
|
|
||||||
|
|
||||||
A patent license is "discriminatory" if it does not include within
|
|
||||||
the scope of its coverage, prohibits the exercise of, or is
|
|
||||||
conditioned on the non-exercise of one or more of the rights that are
|
|
||||||
specifically granted under this License. You may not convey a covered
|
|
||||||
work if you are a party to an arrangement with a third party that is
|
|
||||||
in the business of distributing software, under which you make payment
|
|
||||||
to the third party based on the extent of your activity of conveying
|
|
||||||
the work, and under which the third party grants, to any of the
|
|
||||||
parties who would receive the covered work from you, a discriminatory
|
|
||||||
patent license (a) in connection with copies of the covered work
|
|
||||||
conveyed by you (or copies made from those copies), or (b) primarily
|
|
||||||
for and in connection with specific products or compilations that
|
|
||||||
contain the covered work, unless you entered into that arrangement,
|
|
||||||
or that patent license was granted, prior to 28 March 2007.
|
|
||||||
|
|
||||||
Nothing in this License shall be construed as excluding or limiting
|
|
||||||
any implied license or other defenses to infringement that may
|
|
||||||
otherwise be available to you under applicable patent law.
|
|
||||||
|
|
||||||
12. No Surrender of Others' Freedom.
|
|
||||||
|
|
||||||
If conditions are imposed on you (whether by court order, agreement or
|
|
||||||
otherwise) that contradict the conditions of this License, they do not
|
|
||||||
excuse you from the conditions of this License. If you cannot convey a
|
|
||||||
covered work so as to satisfy simultaneously your obligations under this
|
|
||||||
License and any other pertinent obligations, then as a consequence you may
|
|
||||||
not convey it at all. For example, if you agree to terms that obligate you
|
|
||||||
to collect a royalty for further conveying from those to whom you convey
|
|
||||||
the Program, the only way you could satisfy both those terms and this
|
|
||||||
License would be to refrain entirely from conveying the Program.
|
|
||||||
|
|
||||||
13. Use with the GNU Affero General Public License.
|
|
||||||
|
|
||||||
Notwithstanding any other provision of this License, you have
|
|
||||||
permission to link or combine any covered work with a work licensed
|
|
||||||
under version 3 of the GNU Affero General Public License into a single
|
|
||||||
combined work, and to convey the resulting work. The terms of this
|
|
||||||
License will continue to apply to the part which is the covered work,
|
|
||||||
but the special requirements of the GNU Affero General Public License,
|
|
||||||
section 13, concerning interaction through a network will apply to the
|
|
||||||
combination as such.
|
|
||||||
|
|
||||||
14. Revised Versions of this License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions of
|
|
||||||
the GNU General Public License from time to time. Such new versions will
|
|
||||||
be similar in spirit to the present version, but may differ in detail to
|
|
||||||
address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Program specifies that a certain numbered version of the GNU General
|
|
||||||
Public License "or any later version" applies to it, you have the
|
|
||||||
option of following the terms and conditions either of that numbered
|
|
||||||
version or of any later version published by the Free Software
|
|
||||||
Foundation. If the Program does not specify a version number of the
|
|
||||||
GNU General Public License, you may choose any version ever published
|
|
||||||
by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Program specifies that a proxy can decide which future
|
|
||||||
versions of the GNU General Public License can be used, that proxy's
|
|
||||||
public statement of acceptance of a version permanently authorizes you
|
|
||||||
to choose that version for the Program.
|
|
||||||
|
|
||||||
Later license versions may give you additional or different
|
|
||||||
permissions. However, no additional obligations are imposed on any
|
|
||||||
author or copyright holder as a result of your choosing to follow a
|
|
||||||
later version.
|
|
||||||
|
|
||||||
15. Disclaimer of Warranty.
|
|
||||||
|
|
||||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
|
||||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
|
||||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
|
||||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
||||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
|
||||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
|
||||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
|
||||||
|
|
||||||
16. Limitation of Liability.
|
|
||||||
|
|
||||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
|
||||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
|
||||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
|
||||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
|
||||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
|
||||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
|
||||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
|
||||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
|
||||||
SUCH DAMAGES.
|
|
||||||
|
|
||||||
17. Interpretation of Sections 15 and 16.
|
|
||||||
|
|
||||||
If the disclaimer of warranty and limitation of liability provided
|
|
||||||
above cannot be given local legal effect according to their terms,
|
|
||||||
reviewing courts shall apply local law that most closely approximates
|
|
||||||
an absolute waiver of all civil liability in connection with the
|
|
||||||
Program, unless a warranty or assumption of liability accompanies a
|
|
||||||
copy of the Program in return for a fee.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
How to Apply These Terms to Your New Programs
|
|
||||||
|
|
||||||
If you develop a new program, and you want it to be of the greatest
|
|
||||||
possible use to the public, the best way to achieve this is to make it
|
|
||||||
free software which everyone can redistribute and change under these terms.
|
|
||||||
|
|
||||||
To do so, attach the following notices to the program. It is safest
|
|
||||||
to attach them to the start of each source file to most effectively
|
|
||||||
state the exclusion of warranty; and each file should have at least
|
|
||||||
the "copyright" line and a pointer to where the full notice is found.
|
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
|
||||||
Copyright (C) <year> <name of author>
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
Also add information on how to contact you by electronic and paper mail.
|
|
||||||
|
|
||||||
If the program does terminal interaction, make it output a short
|
|
||||||
notice like this when it starts in an interactive mode:
|
|
||||||
|
|
||||||
<program> Copyright (C) <year> <name of author>
|
|
||||||
This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'.
|
|
||||||
This is free software, and you are welcome to redistribute it
|
|
||||||
under certain conditions; type 'show c' for details.
|
|
||||||
|
|
||||||
The hypothetical commands 'show w' and 'show c' should show the appropriate
|
|
||||||
parts of the General Public License. Of course, your program's commands
|
|
||||||
might be different; for a GUI interface, you would use an "about box".
|
|
||||||
|
|
||||||
You should also get your employer (if you work as a programmer) or school,
|
|
||||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
|
||||||
For more information on this, and how to apply and follow the GNU GPL, see
|
|
||||||
<http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
The GNU General Public License does not permit incorporating your program
|
|
||||||
into proprietary programs. If your program is a subroutine library, you
|
|
||||||
may consider it more useful to permit linking proprietary applications with
|
|
||||||
the library. If this is what you want to do, use the GNU Lesser General
|
|
||||||
Public License instead of this License. But first, please read
|
|
||||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,186 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initLgpl() {
|
|
||||||
Licenses["lgpl"] = License{
|
|
||||||
Name: "GNU Lesser General Public License",
|
|
||||||
PossibleMatches: []string{"lgpl", "lesser gpl", "gnu lgpl"},
|
|
||||||
Header: `
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
|
||||||
it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
|
||||||
(at your option) any later version.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
GNU Lesser General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU Lesser General Public License
|
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.`,
|
|
||||||
Text: ` GNU LESSER GENERAL PUBLIC LICENSE
|
|
||||||
Version 3, 29 June 2007
|
|
||||||
|
|
||||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
|
||||||
of this license document, but changing it is not allowed.
|
|
||||||
|
|
||||||
|
|
||||||
This version of the GNU Lesser General Public License incorporates
|
|
||||||
the terms and conditions of version 3 of the GNU General Public
|
|
||||||
License, supplemented by the additional permissions listed below.
|
|
||||||
|
|
||||||
0. Additional Definitions.
|
|
||||||
|
|
||||||
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
||||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
||||||
General Public License.
|
|
||||||
|
|
||||||
"The Library" refers to a covered work governed by this License,
|
|
||||||
other than an Application or a Combined Work as defined below.
|
|
||||||
|
|
||||||
An "Application" is any work that makes use of an interface provided
|
|
||||||
by the Library, but which is not otherwise based on the Library.
|
|
||||||
Defining a subclass of a class defined by the Library is deemed a mode
|
|
||||||
of using an interface provided by the Library.
|
|
||||||
|
|
||||||
A "Combined Work" is a work produced by combining or linking an
|
|
||||||
Application with the Library. The particular version of the Library
|
|
||||||
with which the Combined Work was made is also called the "Linked
|
|
||||||
Version".
|
|
||||||
|
|
||||||
The "Minimal Corresponding Source" for a Combined Work means the
|
|
||||||
Corresponding Source for the Combined Work, excluding any source code
|
|
||||||
for portions of the Combined Work that, considered in isolation, are
|
|
||||||
based on the Application, and not on the Linked Version.
|
|
||||||
|
|
||||||
The "Corresponding Application Code" for a Combined Work means the
|
|
||||||
object code and/or source code for the Application, including any data
|
|
||||||
and utility programs needed for reproducing the Combined Work from the
|
|
||||||
Application, but excluding the System Libraries of the Combined Work.
|
|
||||||
|
|
||||||
1. Exception to Section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
You may convey a covered work under sections 3 and 4 of this License
|
|
||||||
without being bound by section 3 of the GNU GPL.
|
|
||||||
|
|
||||||
2. Conveying Modified Versions.
|
|
||||||
|
|
||||||
If you modify a copy of the Library, and, in your modifications, a
|
|
||||||
facility refers to a function or data to be supplied by an Application
|
|
||||||
that uses the facility (other than as an argument passed when the
|
|
||||||
facility is invoked), then you may convey a copy of the modified
|
|
||||||
version:
|
|
||||||
|
|
||||||
a) under this License, provided that you make a good faith effort to
|
|
||||||
ensure that, in the event an Application does not supply the
|
|
||||||
function or data, the facility still operates, and performs
|
|
||||||
whatever part of its purpose remains meaningful, or
|
|
||||||
|
|
||||||
b) under the GNU GPL, with none of the additional permissions of
|
|
||||||
this License applicable to that copy.
|
|
||||||
|
|
||||||
3. Object Code Incorporating Material from Library Header Files.
|
|
||||||
|
|
||||||
The object code form of an Application may incorporate material from
|
|
||||||
a header file that is part of the Library. You may convey such object
|
|
||||||
code under terms of your choice, provided that, if the incorporated
|
|
||||||
material is not limited to numerical parameters, data structure
|
|
||||||
layouts and accessors, or small macros, inline functions and templates
|
|
||||||
(ten or fewer lines in length), you do both of the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the object code that the
|
|
||||||
Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
4. Combined Works.
|
|
||||||
|
|
||||||
You may convey a Combined Work under terms of your choice that,
|
|
||||||
taken together, effectively do not restrict modification of the
|
|
||||||
portions of the Library contained in the Combined Work and reverse
|
|
||||||
engineering for debugging such modifications, if you also do each of
|
|
||||||
the following:
|
|
||||||
|
|
||||||
a) Give prominent notice with each copy of the Combined Work that
|
|
||||||
the Library is used in it and that the Library and its use are
|
|
||||||
covered by this License.
|
|
||||||
|
|
||||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
||||||
document.
|
|
||||||
|
|
||||||
c) For a Combined Work that displays copyright notices during
|
|
||||||
execution, include the copyright notice for the Library among
|
|
||||||
these notices, as well as a reference directing the user to the
|
|
||||||
copies of the GNU GPL and this license document.
|
|
||||||
|
|
||||||
d) Do one of the following:
|
|
||||||
|
|
||||||
0) Convey the Minimal Corresponding Source under the terms of this
|
|
||||||
License, and the Corresponding Application Code in a form
|
|
||||||
suitable for, and under terms that permit, the user to
|
|
||||||
recombine or relink the Application with a modified version of
|
|
||||||
the Linked Version to produce a modified Combined Work, in the
|
|
||||||
manner specified by section 6 of the GNU GPL for conveying
|
|
||||||
Corresponding Source.
|
|
||||||
|
|
||||||
1) Use a suitable shared library mechanism for linking with the
|
|
||||||
Library. A suitable mechanism is one that (a) uses at run time
|
|
||||||
a copy of the Library already present on the user's computer
|
|
||||||
system, and (b) will operate properly with a modified version
|
|
||||||
of the Library that is interface-compatible with the Linked
|
|
||||||
Version.
|
|
||||||
|
|
||||||
e) Provide Installation Information, but only if you would otherwise
|
|
||||||
be required to provide such information under section 6 of the
|
|
||||||
GNU GPL, and only to the extent that such information is
|
|
||||||
necessary to install and execute a modified version of the
|
|
||||||
Combined Work produced by recombining or relinking the
|
|
||||||
Application with a modified version of the Linked Version. (If
|
|
||||||
you use option 4d0, the Installation Information must accompany
|
|
||||||
the Minimal Corresponding Source and Corresponding Application
|
|
||||||
Code. If you use option 4d1, you must provide the Installation
|
|
||||||
Information in the manner specified by section 6 of the GNU GPL
|
|
||||||
for conveying Corresponding Source.)
|
|
||||||
|
|
||||||
5. Combined Libraries.
|
|
||||||
|
|
||||||
You may place library facilities that are a work based on the
|
|
||||||
Library side by side in a single library together with other library
|
|
||||||
facilities that are not Applications and are not covered by this
|
|
||||||
License, and convey such a combined library under terms of your
|
|
||||||
choice, if you do both of the following:
|
|
||||||
|
|
||||||
a) Accompany the combined library with a copy of the same work based
|
|
||||||
on the Library, uncombined with any other library facilities,
|
|
||||||
conveyed under the terms of this License.
|
|
||||||
|
|
||||||
b) Give prominent notice with the combined library that part of it
|
|
||||||
is a work based on the Library, and explaining where to find the
|
|
||||||
accompanying uncombined form of the same work.
|
|
||||||
|
|
||||||
6. Revised Versions of the GNU Lesser General Public License.
|
|
||||||
|
|
||||||
The Free Software Foundation may publish revised and/or new versions
|
|
||||||
of the GNU Lesser General Public License from time to time. Such new
|
|
||||||
versions will be similar in spirit to the present version, but may
|
|
||||||
differ in detail to address new problems or concerns.
|
|
||||||
|
|
||||||
Each version is given a distinguishing version number. If the
|
|
||||||
Library as you received it specifies that a certain numbered version
|
|
||||||
of the GNU Lesser General Public License "or any later version"
|
|
||||||
applies to it, you have the option of following the terms and
|
|
||||||
conditions either of that published version or of any later version
|
|
||||||
published by the Free Software Foundation. If the Library as you
|
|
||||||
received it does not specify a version number of the GNU Lesser
|
|
||||||
General Public License, you may choose any version of the GNU Lesser
|
|
||||||
General Public License ever published by the Free Software Foundation.
|
|
||||||
|
|
||||||
If the Library as you received it specifies that a proxy can decide
|
|
||||||
whether future versions of the GNU Lesser General Public License shall
|
|
||||||
apply, that proxy's public statement of acceptance of any version is
|
|
||||||
permanent authorization for you to choose that version for the
|
|
||||||
Library.`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,63 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
func initMit() {
|
|
||||||
Licenses["mit"] = License{
|
|
||||||
Name: "MIT License",
|
|
||||||
PossibleMatches: []string{"mit"},
|
|
||||||
Header: `
|
|
||||||
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.`,
|
|
||||||
Text: `The MIT License (MIT)
|
|
||||||
|
|
||||||
{{ .copyright }}
|
|
||||||
|
|
||||||
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.
|
|
||||||
`,
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,120 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
// Parts inspired by https://github.com/ryanuber/go-license
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Licenses contains all possible licenses a user can choose from.
|
|
||||||
var Licenses = make(map[string]License)
|
|
||||||
|
|
||||||
// License represents a software license agreement, containing the Name of
|
|
||||||
// the license, its possible matches (on the command line as given to cobra),
|
|
||||||
// the header to be used with each file on the file's creating, and the text
|
|
||||||
// of the license
|
|
||||||
type License struct {
|
|
||||||
Name string // The type of license in use
|
|
||||||
PossibleMatches []string // Similar names to guess
|
|
||||||
Text string // License text data
|
|
||||||
Header string // License header for source files
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Allows a user to not use a license.
|
|
||||||
Licenses["none"] = License{"None", []string{"none", "false"}, "", ""}
|
|
||||||
|
|
||||||
initApache2()
|
|
||||||
initMit()
|
|
||||||
initBsdClause3()
|
|
||||||
initBsdClause2()
|
|
||||||
initGpl2()
|
|
||||||
initGpl3()
|
|
||||||
initLgpl()
|
|
||||||
initAgpl()
|
|
||||||
}
|
|
||||||
|
|
||||||
// getLicense returns license specified by user in flag or in config.
|
|
||||||
// If user didn't specify the license, it returns Apache License 2.0.
|
|
||||||
//
|
|
||||||
// TODO: Inspect project for existing license
|
|
||||||
func getLicense() License {
|
|
||||||
// If explicitly flagged, use that.
|
|
||||||
if userLicense != "" {
|
|
||||||
return findLicense(userLicense)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If user wants to have custom license, use that.
|
|
||||||
if viper.IsSet("license.header") || viper.IsSet("license.text") {
|
|
||||||
return License{Header: viper.GetString("license.header"),
|
|
||||||
Text: viper.GetString("license.text")}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If user wants to have built-in license, use that.
|
|
||||||
if viper.IsSet("license") {
|
|
||||||
return findLicense(viper.GetString("license"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// If user didn't set any license, use Apache 2.0 by default.
|
|
||||||
return Licenses["apache"]
|
|
||||||
}
|
|
||||||
|
|
||||||
func copyrightLine() string {
|
|
||||||
author := viper.GetString("author")
|
|
||||||
|
|
||||||
year := viper.GetString("year") // For tests.
|
|
||||||
if year == "" {
|
|
||||||
year = time.Now().Format("2006")
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Copyright © " + year + " " + author
|
|
||||||
}
|
|
||||||
|
|
||||||
// findLicense looks for License object of built-in licenses.
|
|
||||||
// If it didn't find license, then the app will be terminated and
|
|
||||||
// error will be printed.
|
|
||||||
func findLicense(name string) License {
|
|
||||||
found := matchLicense(name)
|
|
||||||
if found == "" {
|
|
||||||
cobra.CheckErr(fmt.Errorf("unknown license: " + name))
|
|
||||||
}
|
|
||||||
return Licenses[found]
|
|
||||||
}
|
|
||||||
|
|
||||||
// matchLicense compares the given a license name
|
|
||||||
// to PossibleMatches of all built-in licenses.
|
|
||||||
// It returns blank string, if name is blank string or it didn't find
|
|
||||||
// then appropriate match to name.
|
|
||||||
func matchLicense(name string) string {
|
|
||||||
if name == "" {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, lic := range Licenses {
|
|
||||||
for _, match := range lic.PossibleMatches {
|
|
||||||
if strings.EqualFold(name, match) {
|
|
||||||
return key
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ""
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"text/template"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/cobra/cobra/tpl"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Project contains name, license and paths to projects.
|
|
||||||
type Project struct {
|
|
||||||
// v2
|
|
||||||
PkgName string
|
|
||||||
Copyright string
|
|
||||||
AbsolutePath string
|
|
||||||
Legal License
|
|
||||||
Viper bool
|
|
||||||
AppName string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Command struct {
|
|
||||||
CmdName string
|
|
||||||
CmdParent string
|
|
||||||
*Project
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Project) Create() error {
|
|
||||||
// check if AbsolutePath exists
|
|
||||||
if _, err := os.Stat(p.AbsolutePath); os.IsNotExist(err) {
|
|
||||||
// create directory
|
|
||||||
if err := os.Mkdir(p.AbsolutePath, 0754); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// create main.go
|
|
||||||
mainFile, err := os.Create(fmt.Sprintf("%s/main.go", p.AbsolutePath))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer mainFile.Close()
|
|
||||||
|
|
||||||
mainTemplate := template.Must(template.New("main").Parse(string(tpl.MainTemplate())))
|
|
||||||
err = mainTemplate.Execute(mainFile, p)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create cmd/root.go
|
|
||||||
if _, err = os.Stat(fmt.Sprintf("%s/cmd", p.AbsolutePath)); os.IsNotExist(err) {
|
|
||||||
cobra.CheckErr(os.Mkdir(fmt.Sprintf("%s/cmd", p.AbsolutePath), 0751))
|
|
||||||
}
|
|
||||||
rootFile, err := os.Create(fmt.Sprintf("%s/cmd/root.go", p.AbsolutePath))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer rootFile.Close()
|
|
||||||
|
|
||||||
rootTemplate := template.Must(template.New("root").Parse(string(tpl.RootTemplate())))
|
|
||||||
err = rootTemplate.Execute(rootFile, p)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// create license
|
|
||||||
return p.createLicenseFile()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *Project) createLicenseFile() error {
|
|
||||||
data := map[string]interface{}{
|
|
||||||
"copyright": copyrightLine(),
|
|
||||||
}
|
|
||||||
licenseFile, err := os.Create(fmt.Sprintf("%s/LICENSE", p.AbsolutePath))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer licenseFile.Close()
|
|
||||||
|
|
||||||
licenseTemplate := template.Must(template.New("license").Parse(p.Legal.Text))
|
|
||||||
return licenseTemplate.Execute(licenseFile, data)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Command) Create() error {
|
|
||||||
cmdFile, err := os.Create(fmt.Sprintf("%s/cmd/%s.go", c.AbsolutePath, c.CmdName))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer cmdFile.Close()
|
|
||||||
|
|
||||||
commandTemplate := template.Must(template.New("sub").Parse(string(tpl.AddCommandTemplate())))
|
|
||||||
err = commandTemplate.Execute(cmdFile, c)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
|
@ -1,3 +0,0 @@
|
||||||
package cmd
|
|
||||||
|
|
||||||
/* todo: write tests */
|
|
|
@ -1,79 +0,0 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
|
||||||
//
|
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
// you may not use this file except in compliance with the License.
|
|
||||||
// You may obtain a copy of the License at
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// Used for flags.
|
|
||||||
cfgFile string
|
|
||||||
userLicense string
|
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
|
||||||
Use: "cobra",
|
|
||||||
Short: "A generator for Cobra based Applications",
|
|
||||||
Long: `Cobra is a CLI library for Go that empowers applications.
|
|
||||||
This application is a tool to generate the needed files
|
|
||||||
to quickly create a Cobra application.`,
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Execute executes the root command.
|
|
||||||
func Execute() error {
|
|
||||||
return rootCmd.Execute()
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cobra.OnInitialize(initConfig)
|
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cobra.yaml)")
|
|
||||||
rootCmd.PersistentFlags().StringP("author", "a", "YOUR NAME", "author name for copyright attribution")
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&userLicense, "license", "l", "", "name of license for the project")
|
|
||||||
rootCmd.PersistentFlags().Bool("viper", true, "use Viper for configuration")
|
|
||||||
cobra.CheckErr(viper.BindPFlag("author", rootCmd.PersistentFlags().Lookup("author")))
|
|
||||||
cobra.CheckErr(viper.BindPFlag("useViper", rootCmd.PersistentFlags().Lookup("viper")))
|
|
||||||
viper.SetDefault("author", "NAME HERE <EMAIL ADDRESS>")
|
|
||||||
viper.SetDefault("license", "apache")
|
|
||||||
|
|
||||||
rootCmd.AddCommand(addCmd)
|
|
||||||
rootCmd.AddCommand(initCmd)
|
|
||||||
}
|
|
||||||
|
|
||||||
func initConfig() {
|
|
||||||
if cfgFile != "" {
|
|
||||||
// Use config file from the flag.
|
|
||||||
viper.SetConfigFile(cfgFile)
|
|
||||||
} else {
|
|
||||||
// Find home directory.
|
|
||||||
home, err := os.UserHomeDir()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
// Search config in home directory with name ".cobra" (without extension).
|
|
||||||
viper.AddConfigPath(home)
|
|
||||||
viper.SetConfigType("yaml")
|
|
||||||
viper.SetConfigName(".cobra")
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.AutomaticEnv()
|
|
||||||
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
|
||||||
fmt.Println("Using config file:", viper.ConfigFileUsed())
|
|
||||||
}
|
|
||||||
}
|
|
202
cobra/cmd/testdata/LICENSE.golden
vendored
202
cobra/cmd/testdata/LICENSE.golden
vendored
|
@ -1,202 +0,0 @@
|
||||||
|
|
||||||
Apache License
|
|
||||||
Version 2.0, January 2004
|
|
||||||
http://www.apache.org/licenses/
|
|
||||||
|
|
||||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
||||||
|
|
||||||
1. Definitions.
|
|
||||||
|
|
||||||
"License" shall mean the terms and conditions for use, reproduction,
|
|
||||||
and distribution as defined by Sections 1 through 9 of this document.
|
|
||||||
|
|
||||||
"Licensor" shall mean the copyright owner or entity authorized by
|
|
||||||
the copyright owner that is granting the License.
|
|
||||||
|
|
||||||
"Legal Entity" shall mean the union of the acting entity and all
|
|
||||||
other entities that control, are controlled by, or are under common
|
|
||||||
control with that entity. For the purposes of this definition,
|
|
||||||
"control" means (i) the power, direct or indirect, to cause the
|
|
||||||
direction or management of such entity, whether by contract or
|
|
||||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
||||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
||||||
|
|
||||||
"You" (or "Your") shall mean an individual or Legal Entity
|
|
||||||
exercising permissions granted by this License.
|
|
||||||
|
|
||||||
"Source" form shall mean the preferred form for making modifications,
|
|
||||||
including but not limited to software source code, documentation
|
|
||||||
source, and configuration files.
|
|
||||||
|
|
||||||
"Object" form shall mean any form resulting from mechanical
|
|
||||||
transformation or translation of a Source form, including but
|
|
||||||
not limited to compiled object code, generated documentation,
|
|
||||||
and conversions to other media types.
|
|
||||||
|
|
||||||
"Work" shall mean the work of authorship, whether in Source or
|
|
||||||
Object form, made available under the License, as indicated by a
|
|
||||||
copyright notice that is included in or attached to the work
|
|
||||||
(an example is provided in the Appendix below).
|
|
||||||
|
|
||||||
"Derivative Works" shall mean any work, whether in Source or Object
|
|
||||||
form, that is based on (or derived from) the Work and for which the
|
|
||||||
editorial revisions, annotations, elaborations, or other modifications
|
|
||||||
represent, as a whole, an original work of authorship. For the purposes
|
|
||||||
of this License, Derivative Works shall not include works that remain
|
|
||||||
separable from, or merely link (or bind by name) to the interfaces of,
|
|
||||||
the Work and Derivative Works thereof.
|
|
||||||
|
|
||||||
"Contribution" shall mean any work of authorship, including
|
|
||||||
the original version of the Work and any modifications or additions
|
|
||||||
to that Work or Derivative Works thereof, that is intentionally
|
|
||||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
||||||
or by an individual or Legal Entity authorized to submit on behalf of
|
|
||||||
the copyright owner. For the purposes of this definition, "submitted"
|
|
||||||
means any form of electronic, verbal, or written communication sent
|
|
||||||
to the Licensor or its representatives, including but not limited to
|
|
||||||
communication on electronic mailing lists, source code control systems,
|
|
||||||
and issue tracking systems that are managed by, or on behalf of, the
|
|
||||||
Licensor for the purpose of discussing and improving the Work, but
|
|
||||||
excluding communication that is conspicuously marked or otherwise
|
|
||||||
designated in writing by the copyright owner as "Not a Contribution."
|
|
||||||
|
|
||||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
||||||
on behalf of whom a Contribution has been received by Licensor and
|
|
||||||
subsequently incorporated within the Work.
|
|
||||||
|
|
||||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
copyright license to reproduce, prepare Derivative Works of,
|
|
||||||
publicly display, publicly perform, sublicense, and distribute the
|
|
||||||
Work and such Derivative Works in Source or Object form.
|
|
||||||
|
|
||||||
3. Grant of Patent License. Subject to the terms and conditions of
|
|
||||||
this License, each Contributor hereby grants to You a perpetual,
|
|
||||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
||||||
(except as stated in this section) patent license to make, have made,
|
|
||||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
||||||
where such license applies only to those patent claims licensable
|
|
||||||
by such Contributor that are necessarily infringed by their
|
|
||||||
Contribution(s) alone or by combination of their Contribution(s)
|
|
||||||
with the Work to which such Contribution(s) was submitted. If You
|
|
||||||
institute patent litigation against any entity (including a
|
|
||||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
||||||
or a Contribution incorporated within the Work constitutes direct
|
|
||||||
or contributory patent infringement, then any patent licenses
|
|
||||||
granted to You under this License for that Work shall terminate
|
|
||||||
as of the date such litigation is filed.
|
|
||||||
|
|
||||||
4. Redistribution. You may reproduce and distribute copies of the
|
|
||||||
Work or Derivative Works thereof in any medium, with or without
|
|
||||||
modifications, and in Source or Object form, provided that You
|
|
||||||
meet the following conditions:
|
|
||||||
|
|
||||||
(a) You must give any other recipients of the Work or
|
|
||||||
Derivative Works a copy of this License; and
|
|
||||||
|
|
||||||
(b) You must cause any modified files to carry prominent notices
|
|
||||||
stating that You changed the files; and
|
|
||||||
|
|
||||||
(c) You must retain, in the Source form of any Derivative Works
|
|
||||||
that You distribute, all copyright, patent, trademark, and
|
|
||||||
attribution notices from the Source form of the Work,
|
|
||||||
excluding those notices that do not pertain to any part of
|
|
||||||
the Derivative Works; and
|
|
||||||
|
|
||||||
(d) If the Work includes a "NOTICE" text file as part of its
|
|
||||||
distribution, then any Derivative Works that You distribute must
|
|
||||||
include a readable copy of the attribution notices contained
|
|
||||||
within such NOTICE file, excluding those notices that do not
|
|
||||||
pertain to any part of the Derivative Works, in at least one
|
|
||||||
of the following places: within a NOTICE text file distributed
|
|
||||||
as part of the Derivative Works; within the Source form or
|
|
||||||
documentation, if provided along with the Derivative Works; or,
|
|
||||||
within a display generated by the Derivative Works, if and
|
|
||||||
wherever such third-party notices normally appear. The contents
|
|
||||||
of the NOTICE file are for informational purposes only and
|
|
||||||
do not modify the License. You may add Your own attribution
|
|
||||||
notices within Derivative Works that You distribute, alongside
|
|
||||||
or as an addendum to the NOTICE text from the Work, provided
|
|
||||||
that such additional attribution notices cannot be construed
|
|
||||||
as modifying the License.
|
|
||||||
|
|
||||||
You may add Your own copyright statement to Your modifications and
|
|
||||||
may provide additional or different license terms and conditions
|
|
||||||
for use, reproduction, or distribution of Your modifications, or
|
|
||||||
for any such Derivative Works as a whole, provided Your use,
|
|
||||||
reproduction, and distribution of the Work otherwise complies with
|
|
||||||
the conditions stated in this License.
|
|
||||||
|
|
||||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
||||||
any Contribution intentionally submitted for inclusion in the Work
|
|
||||||
by You to the Licensor shall be under the terms and conditions of
|
|
||||||
this License, without any additional terms or conditions.
|
|
||||||
Notwithstanding the above, nothing herein shall supersede or modify
|
|
||||||
the terms of any separate license agreement you may have executed
|
|
||||||
with Licensor regarding such Contributions.
|
|
||||||
|
|
||||||
6. Trademarks. This License does not grant permission to use the trade
|
|
||||||
names, trademarks, service marks, or product names of the Licensor,
|
|
||||||
except as required for reasonable and customary use in describing the
|
|
||||||
origin of the Work and reproducing the content of the NOTICE file.
|
|
||||||
|
|
||||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
||||||
agreed to in writing, Licensor provides the Work (and each
|
|
||||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
||||||
implied, including, without limitation, any warranties or conditions
|
|
||||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
||||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
||||||
appropriateness of using or redistributing the Work and assume any
|
|
||||||
risks associated with Your exercise of permissions under this License.
|
|
||||||
|
|
||||||
8. Limitation of Liability. In no event and under no legal theory,
|
|
||||||
whether in tort (including negligence), contract, or otherwise,
|
|
||||||
unless required by applicable law (such as deliberate and grossly
|
|
||||||
negligent acts) or agreed to in writing, shall any Contributor be
|
|
||||||
liable to You for damages, including any direct, indirect, special,
|
|
||||||
incidental, or consequential damages of any character arising as a
|
|
||||||
result of this License or out of the use or inability to use the
|
|
||||||
Work (including but not limited to damages for loss of goodwill,
|
|
||||||
work stoppage, computer failure or malfunction, or any and all
|
|
||||||
other commercial damages or losses), even if such Contributor
|
|
||||||
has been advised of the possibility of such damages.
|
|
||||||
|
|
||||||
9. Accepting Warranty or Additional Liability. While redistributing
|
|
||||||
the Work or Derivative Works thereof, You may choose to offer,
|
|
||||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
||||||
or other liability obligations and/or rights consistent with this
|
|
||||||
License. However, in accepting such obligations, You may act only
|
|
||||||
on Your own behalf and on Your sole responsibility, not on behalf
|
|
||||||
of any other Contributor, and only if You agree to indemnify,
|
|
||||||
defend, and hold each Contributor harmless for any liability
|
|
||||||
incurred by, or claims asserted against, such Contributor by reason
|
|
||||||
of your accepting any such warranty or additional liability.
|
|
||||||
|
|
||||||
END OF TERMS AND CONDITIONS
|
|
||||||
|
|
||||||
APPENDIX: How to apply the Apache License to your work.
|
|
||||||
|
|
||||||
To apply the Apache License to your work, attach the following
|
|
||||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
||||||
replaced with your own identifying information. (Don't include
|
|
||||||
the brackets!) The text should be enclosed in the appropriate
|
|
||||||
comment syntax for the file format. We also recommend that a
|
|
||||||
file or class name and description of purpose be included on the
|
|
||||||
same "printed page" as the copyright notice for easier
|
|
||||||
identification within third-party archives.
|
|
||||||
|
|
||||||
Copyright [yyyy] [name of copyright owner]
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
22
cobra/cmd/testdata/main.go.golden
vendored
22
cobra/cmd/testdata/main.go.golden
vendored
|
@ -1,22 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "github.com/spf13/testproject/cmd"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
cmd.Execute()
|
|
||||||
}
|
|
85
cobra/cmd/testdata/root.go.golden
vendored
85
cobra/cmd/testdata/root.go.golden
vendored
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
|
|
||||||
"github.com/spf13/viper"
|
|
||||||
)
|
|
||||||
|
|
||||||
var cfgFile string
|
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
|
||||||
var rootCmd = &cobra.Command{
|
|
||||||
Use: "testproject",
|
|
||||||
Short: "A brief description of your application",
|
|
||||||
Long: `A longer description that spans multiple lines and likely contains
|
|
||||||
examples and usage of using your application. For example:
|
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
|
||||||
This application is a tool to generate the needed files
|
|
||||||
to quickly create a Cobra application.`,
|
|
||||||
// Uncomment the following line if your bare application
|
|
||||||
// has an action associated with it:
|
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
||||||
func Execute() {
|
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
cobra.OnInitialize(initConfig)
|
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
|
||||||
// will be global for your application.
|
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.testproject.yaml)")
|
|
||||||
|
|
||||||
// Cobra also supports local flags, which will only run
|
|
||||||
// when this action is called directly.
|
|
||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
||||||
}
|
|
||||||
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
|
||||||
func initConfig() {
|
|
||||||
if cfgFile != "" {
|
|
||||||
// Use config file from the flag.
|
|
||||||
viper.SetConfigFile(cfgFile)
|
|
||||||
} else {
|
|
||||||
// Find home directory.
|
|
||||||
home, err := os.UserHomeDir()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
// Search config in home directory with name ".testproject" (without extension).
|
|
||||||
viper.AddConfigPath(home)
|
|
||||||
viper.SetConfigType("yaml")
|
|
||||||
viper.SetConfigName(".testproject")
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
|
||||||
|
|
||||||
// If a config file is found, read it in.
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
|
||||||
}
|
|
||||||
}
|
|
51
cobra/cmd/testdata/test.go.golden
vendored
51
cobra/cmd/testdata/test.go.golden
vendored
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
|
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
you may not use this file except in compliance with the License.
|
|
||||||
You may obtain a copy of the License at
|
|
||||||
|
|
||||||
http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
|
|
||||||
Unless required by applicable law or agreed to in writing, software
|
|
||||||
distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
See the License for the specific language governing permissions and
|
|
||||||
limitations under the License.
|
|
||||||
*/
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
// testCmd represents the test command
|
|
||||||
var testCmd = &cobra.Command{
|
|
||||||
Use: "test",
|
|
||||||
Short: "A brief description of your command",
|
|
||||||
Long: `A longer description that spans multiple lines and likely contains examples
|
|
||||||
and usage of using your command. For example:
|
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
|
||||||
This application is a tool to generate the needed files
|
|
||||||
to quickly create a Cobra application.`,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("test called")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
rootCmd.AddCommand(testCmd)
|
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
|
||||||
|
|
||||||
// Cobra supports Persistent Flags which will work for this command
|
|
||||||
// and all subcommands, e.g.:
|
|
||||||
// testCmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
||||||
|
|
||||||
// Cobra supports local flags which will only run when this command
|
|
||||||
// is called directly, e.g.:
|
|
||||||
// testCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
||||||
}
|
|
|
@ -1,145 +0,0 @@
|
||||||
package tpl
|
|
||||||
|
|
||||||
func MainTemplate() []byte {
|
|
||||||
return []byte(`/*
|
|
||||||
{{ .Copyright }}
|
|
||||||
{{ if .Legal.Header }}{{ .Legal.Header }}{{ end }}
|
|
||||||
*/
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "{{ .PkgName }}/cmd"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
cmd.Execute()
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func RootTemplate() []byte {
|
|
||||||
return []byte(`/*
|
|
||||||
{{ .Copyright }}
|
|
||||||
{{ if .Legal.Header }}{{ .Legal.Header }}{{ end }}
|
|
||||||
*/
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"os"
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
{{ if .Viper }}
|
|
||||||
"github.com/spf13/viper"{{ end }}
|
|
||||||
)
|
|
||||||
|
|
||||||
{{ if .Viper -}}
|
|
||||||
var cfgFile string
|
|
||||||
{{- end }}
|
|
||||||
|
|
||||||
// rootCmd represents the base command when called without any subcommands
|
|
||||||
var rootCmd = &cobra.Command{
|
|
||||||
Use: "{{ .AppName }}",
|
|
||||||
Short: "A brief description of your application",
|
|
||||||
Long: ` + "`" + `A longer description that spans multiple lines and likely contains
|
|
||||||
examples and usage of using your application. For example:
|
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
|
||||||
This application is a tool to generate the needed files
|
|
||||||
to quickly create a Cobra application.` + "`" + `,
|
|
||||||
// Uncomment the following line if your bare application
|
|
||||||
// has an action associated with it:
|
|
||||||
// Run: func(cmd *cobra.Command, args []string) { },
|
|
||||||
}
|
|
||||||
|
|
||||||
// Execute adds all child commands to the root command and sets flags appropriately.
|
|
||||||
// This is called by main.main(). It only needs to happen once to the rootCmd.
|
|
||||||
func Execute() {
|
|
||||||
cobra.CheckErr(rootCmd.Execute())
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
{{- if .Viper }}
|
|
||||||
cobra.OnInitialize(initConfig)
|
|
||||||
{{ end }}
|
|
||||||
// Here you will define your flags and configuration settings.
|
|
||||||
// Cobra supports persistent flags, which, if defined here,
|
|
||||||
// will be global for your application.
|
|
||||||
{{ if .Viper }}
|
|
||||||
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.{{ .AppName }}.yaml)")
|
|
||||||
{{ else }}
|
|
||||||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.{{ .AppName }}.yaml)")
|
|
||||||
{{ end }}
|
|
||||||
// Cobra also supports local flags, which will only run
|
|
||||||
// when this action is called directly.
|
|
||||||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
||||||
}
|
|
||||||
|
|
||||||
{{ if .Viper -}}
|
|
||||||
// initConfig reads in config file and ENV variables if set.
|
|
||||||
func initConfig() {
|
|
||||||
if cfgFile != "" {
|
|
||||||
// Use config file from the flag.
|
|
||||||
viper.SetConfigFile(cfgFile)
|
|
||||||
} else {
|
|
||||||
// Find home directory.
|
|
||||||
home, err := os.UserHomeDir()
|
|
||||||
cobra.CheckErr(err)
|
|
||||||
|
|
||||||
// Search config in home directory with name ".{{ .AppName }}" (without extension).
|
|
||||||
viper.AddConfigPath(home)
|
|
||||||
viper.SetConfigType("yaml")
|
|
||||||
viper.SetConfigName(".{{ .AppName }}")
|
|
||||||
}
|
|
||||||
|
|
||||||
viper.AutomaticEnv() // read in environment variables that match
|
|
||||||
|
|
||||||
// If a config file is found, read it in.
|
|
||||||
if err := viper.ReadInConfig(); err == nil {
|
|
||||||
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{{- end }}
|
|
||||||
`)
|
|
||||||
}
|
|
||||||
|
|
||||||
func AddCommandTemplate() []byte {
|
|
||||||
return []byte(`/*
|
|
||||||
{{ .Project.Copyright }}
|
|
||||||
{{ if .Legal.Header }}{{ .Legal.Header }}{{ end }}
|
|
||||||
*/
|
|
||||||
package cmd
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
|
||||||
)
|
|
||||||
|
|
||||||
// {{ .CmdName }}Cmd represents the {{ .CmdName }} command
|
|
||||||
var {{ .CmdName }}Cmd = &cobra.Command{
|
|
||||||
Use: "{{ .CmdName }}",
|
|
||||||
Short: "A brief description of your command",
|
|
||||||
Long: ` + "`" + `A longer description that spans multiple lines and likely contains examples
|
|
||||||
and usage of using your command. For example:
|
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
|
||||||
This application is a tool to generate the needed files
|
|
||||||
to quickly create a Cobra application.` + "`" + `,
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
|
||||||
fmt.Println("{{ .CmdName }} called")
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
{{ .CmdParent }}.AddCommand({{ .CmdName }}Cmd)
|
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
|
||||||
|
|
||||||
// Cobra supports Persistent Flags which will work for this command
|
|
||||||
// and all subcommands, e.g.:
|
|
||||||
// {{ .CmdName }}Cmd.PersistentFlags().String("foo", "", "A help for foo")
|
|
||||||
|
|
||||||
// Cobra supports local flags which will only run when this command
|
|
||||||
// is called directly, e.g.:
|
|
||||||
// {{ .CmdName }}Cmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
|
||||||
}
|
|
||||||
`)
|
|
||||||
}
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
65
command.go
65
command.go
|
@ -1,8 +1,9 @@
|
||||||
// Copyright © 2013 Steve Francia <spf@spf13.com>.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -18,6 +19,7 @@ package cobra
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
@ -28,6 +30,8 @@ import (
|
||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const FlagSetByCobraAnnotation = "cobra_annotation_flag_set_by_cobra"
|
||||||
|
|
||||||
// FParseErrWhitelist configures Flag parse errors to be ignored
|
// FParseErrWhitelist configures Flag parse errors to be ignored
|
||||||
type FParseErrWhitelist flag.ParseErrorsWhitelist
|
type FParseErrWhitelist flag.ParseErrorsWhitelist
|
||||||
|
|
||||||
|
@ -166,7 +170,7 @@ type Command struct {
|
||||||
// errWriter is a writer defined by the user that replaces stderr
|
// errWriter is a writer defined by the user that replaces stderr
|
||||||
errWriter io.Writer
|
errWriter io.Writer
|
||||||
|
|
||||||
//FParseErrWhitelist flag parse errors to be ignored
|
// FParseErrWhitelist flag parse errors to be ignored
|
||||||
FParseErrWhitelist FParseErrWhitelist
|
FParseErrWhitelist FParseErrWhitelist
|
||||||
|
|
||||||
// CompletionOptions is a set of options to control the handling of shell completion
|
// CompletionOptions is a set of options to control the handling of shell completion
|
||||||
|
@ -224,12 +228,23 @@ type Command struct {
|
||||||
SuggestionsMinimumDistance int
|
SuggestionsMinimumDistance int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context returns underlying command context. If command wasn't
|
// Context returns underlying command context. If command was executed
|
||||||
// executed with ExecuteContext Context returns Background context.
|
// with ExecuteContext or the context was set with SetContext, the
|
||||||
|
// previously set context will be returned. Otherwise, nil is returned.
|
||||||
|
//
|
||||||
|
// Notice that a call to Execute and ExecuteC will replace a nil context of
|
||||||
|
// a command with a context.Background, so a background context will be
|
||||||
|
// returned by Context after one of these functions has been called.
|
||||||
func (c *Command) Context() context.Context {
|
func (c *Command) Context() context.Context {
|
||||||
return c.ctx
|
return c.ctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetContext sets context for the command. This context will be overwritten by
|
||||||
|
// Command.ExecuteContext or Command.ExecuteContextC.
|
||||||
|
func (c *Command) SetContext(ctx context.Context) {
|
||||||
|
c.ctx = ctx
|
||||||
|
}
|
||||||
|
|
||||||
// SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden
|
// SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden
|
||||||
// particularly useful when testing.
|
// particularly useful when testing.
|
||||||
func (c *Command) SetArgs(a []string) {
|
func (c *Command) SetArgs(a []string) {
|
||||||
|
@ -664,7 +679,7 @@ func (c *Command) findSuggestions(arg string) string {
|
||||||
func (c *Command) findNext(next string) *Command {
|
func (c *Command) findNext(next string) *Command {
|
||||||
matches := make([]*Command, 0)
|
matches := make([]*Command, 0)
|
||||||
for _, cmd := range c.commands {
|
for _, cmd := range c.commands {
|
||||||
if cmd.Name() == next || cmd.HasAlias(next) {
|
if commandNameMatches(cmd.Name(), next) || cmd.HasAlias(next) {
|
||||||
cmd.commandCalledAs.name = next
|
cmd.commandCalledAs.name = next
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
@ -821,6 +836,8 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
|
|
||||||
c.preRun()
|
c.preRun()
|
||||||
|
|
||||||
|
defer c.postRun()
|
||||||
|
|
||||||
argWoFlags := c.Flags().Args()
|
argWoFlags := c.Flags().Args()
|
||||||
if c.DisableFlagParsing {
|
if c.DisableFlagParsing {
|
||||||
argWoFlags = a
|
argWoFlags = a
|
||||||
|
@ -849,9 +866,13 @@ func (c *Command) execute(a []string) (err error) {
|
||||||
c.PreRun(c, argWoFlags)
|
c.PreRun(c, argWoFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := c.validateRequiredFlags(); err != nil {
|
if err := c.ValidateRequiredFlags(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := c.ValidateFlagGroups(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if c.RunE != nil {
|
if c.RunE != nil {
|
||||||
if err := c.RunE(c, argWoFlags); err != nil {
|
if err := c.RunE(c, argWoFlags); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -887,6 +908,12 @@ func (c *Command) preRun() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Command) postRun() {
|
||||||
|
for _, x := range finalizers {
|
||||||
|
x()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ExecuteContext is the same as Execute(), but sets the ctx on the command.
|
// ExecuteContext is the same as Execute(), but sets the ctx on the command.
|
||||||
// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle or ValidArgs
|
// Retrieve ctx by calling cmd.Context() inside your *Run lifecycle or ValidArgs
|
||||||
// functions.
|
// functions.
|
||||||
|
@ -975,7 +1002,7 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Always show help if requested, even if SilenceErrors is in
|
// Always show help if requested, even if SilenceErrors is in
|
||||||
// effect
|
// effect
|
||||||
if err == flag.ErrHelp {
|
if errors.Is(err, flag.ErrHelp) {
|
||||||
cmd.HelpFunc()(cmd, args)
|
cmd.HelpFunc()(cmd, args)
|
||||||
return cmd, nil
|
return cmd, nil
|
||||||
}
|
}
|
||||||
|
@ -997,12 +1024,13 @@ func (c *Command) ExecuteC() (cmd *Command, err error) {
|
||||||
|
|
||||||
func (c *Command) ValidateArgs(args []string) error {
|
func (c *Command) ValidateArgs(args []string) error {
|
||||||
if c.Args == nil {
|
if c.Args == nil {
|
||||||
return nil
|
return ArbitraryArgs(c, args)
|
||||||
}
|
}
|
||||||
return c.Args(c, args)
|
return c.Args(c, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) validateRequiredFlags() error {
|
// ValidateRequiredFlags validates all required flags are present and returns an error otherwise
|
||||||
|
func (c *Command) ValidateRequiredFlags() error {
|
||||||
if c.DisableFlagParsing {
|
if c.DisableFlagParsing {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1038,6 +1066,7 @@ func (c *Command) InitDefaultHelpFlag() {
|
||||||
usage += c.Name()
|
usage += c.Name()
|
||||||
}
|
}
|
||||||
c.Flags().BoolP("help", "h", false, usage)
|
c.Flags().BoolP("help", "h", false, usage)
|
||||||
|
_ = c.Flags().SetAnnotation("help", FlagSetByCobraAnnotation, []string{"true"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1063,6 +1092,7 @@ func (c *Command) InitDefaultVersionFlag() {
|
||||||
} else {
|
} else {
|
||||||
c.Flags().Bool("version", false, usage)
|
c.Flags().Bool("version", false, usage)
|
||||||
}
|
}
|
||||||
|
_ = c.Flags().SetAnnotation("version", FlagSetByCobraAnnotation, []string{"true"})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1106,6 +1136,7 @@ Simply type ` + c.Name() + ` help [path to command] for full details.`,
|
||||||
CheckErr(c.Root().Usage())
|
CheckErr(c.Root().Usage())
|
||||||
} else {
|
} else {
|
||||||
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
|
cmd.InitDefaultHelpFlag() // make possible 'help' flag to be shown
|
||||||
|
cmd.InitDefaultVersionFlag() // make possible 'version' flag to be shown
|
||||||
CheckErr(cmd.Help())
|
CheckErr(cmd.Help())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1312,7 +1343,7 @@ func (c *Command) Name() string {
|
||||||
// HasAlias determines if a given string is an alias of the command.
|
// HasAlias determines if a given string is an alias of the command.
|
||||||
func (c *Command) HasAlias(s string) bool {
|
func (c *Command) HasAlias(s string) bool {
|
||||||
for _, a := range c.Aliases {
|
for _, a := range c.Aliases {
|
||||||
if a == s {
|
if commandNameMatches(a, s) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1489,7 +1520,8 @@ func (c *Command) LocalFlags() *flag.FlagSet {
|
||||||
}
|
}
|
||||||
|
|
||||||
addToLocal := func(f *flag.Flag) {
|
addToLocal := func(f *flag.Flag) {
|
||||||
if c.lflags.Lookup(f.Name) == nil && c.parentsPflags.Lookup(f.Name) == nil {
|
// Add the flag if it is not a parent PFlag, or it shadows a parent PFlag
|
||||||
|
if c.lflags.Lookup(f.Name) == nil && f != c.parentsPflags.Lookup(f.Name) {
|
||||||
c.lflags.AddFlag(f)
|
c.lflags.AddFlag(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1678,3 +1710,14 @@ func (c *Command) updateParentsPflags() {
|
||||||
c.parentsPflags.AddFlagSet(parent.PersistentFlags())
|
c.parentsPflags.AddFlagSet(parent.PersistentFlags())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// commandNameMatches checks if two command names are equal
|
||||||
|
// taking into account case sensitivity according to
|
||||||
|
// EnableCaseInsensitive global configuration.
|
||||||
|
func commandNameMatches(s string, t string) bool {
|
||||||
|
if EnableCaseInsensitive {
|
||||||
|
return strings.EqualFold(s, t)
|
||||||
|
}
|
||||||
|
|
||||||
|
return s == t
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,18 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build !windows
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
398
command_test.go
398
command_test.go
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -314,7 +328,7 @@ func TestEnablePrefixMatching(t *testing.T) {
|
||||||
t.Errorf("aCmdArgs expected: %q, got: %q", onetwo, got)
|
t.Errorf("aCmdArgs expected: %q, got: %q", onetwo, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
EnablePrefixMatching = false
|
EnablePrefixMatching = defaultPrefixMatching
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAliasPrefixMatching(t *testing.T) {
|
func TestAliasPrefixMatching(t *testing.T) {
|
||||||
|
@ -349,7 +363,7 @@ func TestAliasPrefixMatching(t *testing.T) {
|
||||||
t.Errorf("timesCmdArgs expected: %v, got: %v", onetwo, got)
|
t.Errorf("timesCmdArgs expected: %v, got: %v", onetwo, got)
|
||||||
}
|
}
|
||||||
|
|
||||||
EnablePrefixMatching = false
|
EnablePrefixMatching = defaultPrefixMatching
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestChildSameName checks the correct behaviour of cobra in cases,
|
// TestChildSameName checks the correct behaviour of cobra in cases,
|
||||||
|
@ -707,10 +721,7 @@ func TestEmptyInputs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOverwrittenFlag(t *testing.T) {
|
func TestChildFlagShadowsParentPersistentFlag(t *testing.T) {
|
||||||
// TODO: This test fails, but should work.
|
|
||||||
t.Skip()
|
|
||||||
|
|
||||||
parent := &Command{Use: "parent", Run: emptyRun}
|
parent := &Command{Use: "parent", Run: emptyRun}
|
||||||
child := &Command{Use: "child", Run: emptyRun}
|
child := &Command{Use: "child", Run: emptyRun}
|
||||||
|
|
||||||
|
@ -732,7 +743,7 @@ func TestOverwrittenFlag(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if childInherited.Lookup("intf") != nil {
|
if childInherited.Lookup("intf") != nil {
|
||||||
t.Errorf(`InheritedFlags should not contain overwritten flag "intf"`)
|
t.Errorf(`InheritedFlags should not contain shadowed flag "intf"`)
|
||||||
}
|
}
|
||||||
if childLocal.Lookup("intf") == nil {
|
if childLocal.Lookup("intf") == nil {
|
||||||
t.Error(`LocalFlags expected to contain "intf", got "nil"`)
|
t.Error(`LocalFlags expected to contain "intf", got "nil"`)
|
||||||
|
@ -887,6 +898,38 @@ func TestHelpCommandExecutedOnChild(t *testing.T) {
|
||||||
checkStringContains(t, output, childCmd.Long)
|
checkStringContains(t, output, childCmd.Long)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHelpCommandExecutedOnChildWithFlagThatShadowsParentFlag(t *testing.T) {
|
||||||
|
parent := &Command{Use: "parent", Run: emptyRun}
|
||||||
|
child := &Command{Use: "child", Run: emptyRun}
|
||||||
|
parent.AddCommand(child)
|
||||||
|
|
||||||
|
parent.PersistentFlags().Bool("foo", false, "parent foo usage")
|
||||||
|
parent.PersistentFlags().Bool("bar", false, "parent bar usage")
|
||||||
|
child.Flags().Bool("foo", false, "child foo usage") // This shadows parent's foo flag
|
||||||
|
child.Flags().Bool("baz", false, "child baz usage")
|
||||||
|
|
||||||
|
got, err := executeCommand(parent, "help", "child")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := `Usage:
|
||||||
|
parent child [flags]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
--baz child baz usage
|
||||||
|
--foo child foo usage
|
||||||
|
-h, --help help for child
|
||||||
|
|
||||||
|
Global Flags:
|
||||||
|
--bar parent bar usage
|
||||||
|
`
|
||||||
|
|
||||||
|
if got != expected {
|
||||||
|
t.Errorf("Help text mismatch.\nExpected:\n%s\n\nGot:\n%s\n", expected, got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSetHelpCommand(t *testing.T) {
|
func TestSetHelpCommand(t *testing.T) {
|
||||||
c := &Command{Use: "c", Run: emptyRun}
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
c.AddCommand(&Command{Use: "empty", Run: emptyRun})
|
c.AddCommand(&Command{Use: "empty", Run: emptyRun})
|
||||||
|
@ -1234,6 +1277,113 @@ func TestSuggestions(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCaseInsensitive(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Run: emptyRun}
|
||||||
|
childCmd := &Command{Use: "child", Run: emptyRun, Aliases: []string{"alternative"}}
|
||||||
|
granchildCmd := &Command{Use: "GRANDCHILD", Run: emptyRun, Aliases: []string{"ALIAS"}}
|
||||||
|
|
||||||
|
childCmd.AddCommand(granchildCmd)
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
args []string
|
||||||
|
failWithoutEnabling bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
args: []string{"child"},
|
||||||
|
failWithoutEnabling: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"CHILD"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"chILD"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"CHIld"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"alternative"},
|
||||||
|
failWithoutEnabling: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"ALTERNATIVE"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"ALTernatIVE"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"alternatiVE"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"child", "GRANDCHILD"},
|
||||||
|
failWithoutEnabling: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"child", "grandchild"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"CHIld", "GRANdchild"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"alternative", "ALIAS"},
|
||||||
|
failWithoutEnabling: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"alternative", "alias"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"CHILD", "alias"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
args: []string{"CHIld", "aliAS"},
|
||||||
|
failWithoutEnabling: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range tests {
|
||||||
|
for _, enableCaseInsensitivity := range []bool{true, false} {
|
||||||
|
EnableCaseInsensitive = enableCaseInsensitivity
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, test.args...)
|
||||||
|
expectedFailure := test.failWithoutEnabling && !enableCaseInsensitivity
|
||||||
|
|
||||||
|
if !expectedFailure && output != "" {
|
||||||
|
t.Errorf("Unexpected output: %v", output)
|
||||||
|
}
|
||||||
|
if !expectedFailure && err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
EnableCaseInsensitive = defaultCaseInsensitive
|
||||||
|
}
|
||||||
|
|
||||||
|
// This test make sure we keep backwards-compatibility with respect
|
||||||
|
// to command names case sensitivity behavior.
|
||||||
|
func TestCaseSensitivityBackwardCompatibility(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Run: emptyRun}
|
||||||
|
childCmd := &Command{Use: "child", Run: emptyRun}
|
||||||
|
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
_, err := executeCommand(rootCmd, strings.ToUpper(childCmd.Use))
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected error on calling a command in upper case while command names are case sensitive. Got nil.")
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestRemoveCommand(t *testing.T) {
|
func TestRemoveCommand(t *testing.T) {
|
||||||
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
childCmd := &Command{Use: "child", Run: emptyRun}
|
childCmd := &Command{Use: "child", Run: emptyRun}
|
||||||
|
@ -1414,16 +1564,16 @@ func TestPersistentHooks(t *testing.T) {
|
||||||
name string
|
name string
|
||||||
got string
|
got string
|
||||||
}{
|
}{
|
||||||
// TODO: currently PersistenPreRun* defined in parent does not
|
// TODO: currently PersistentPreRun* defined in parent does not
|
||||||
// run if the matchin child subcommand has PersistenPreRun.
|
// run if the matching child subcommand has PersistentPreRun.
|
||||||
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
||||||
// this test must be fixed.
|
// this test must be fixed.
|
||||||
{"parentPersPreArgs", parentPersPreArgs},
|
{"parentPersPreArgs", parentPersPreArgs},
|
||||||
{"parentPreArgs", parentPreArgs},
|
{"parentPreArgs", parentPreArgs},
|
||||||
{"parentRunArgs", parentRunArgs},
|
{"parentRunArgs", parentRunArgs},
|
||||||
{"parentPostArgs", parentPostArgs},
|
{"parentPostArgs", parentPostArgs},
|
||||||
// TODO: currently PersistenPostRun* defined in parent does not
|
// TODO: currently PersistentPostRun* defined in parent does not
|
||||||
// run if the matchin child subcommand has PersistenPostRun.
|
// run if the matching child subcommand has PersistentPostRun.
|
||||||
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
// If the behavior changes (https://github.com/spf13/cobra/issues/252)
|
||||||
// this test must be fixed.
|
// this test must be fixed.
|
||||||
{"parentPersPostArgs", parentPersPostArgs},
|
{"parentPersPostArgs", parentPersPostArgs},
|
||||||
|
@ -1593,7 +1743,7 @@ func TestCommandsAreSorted(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnableCommandSorting = true
|
EnableCommandSorting = defaultCommandSorting
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEnableCommandSortingIsDisabled(t *testing.T) {
|
func TestEnableCommandSortingIsDisabled(t *testing.T) {
|
||||||
|
@ -1614,7 +1764,7 @@ func TestEnableCommandSortingIsDisabled(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnableCommandSorting = true
|
EnableCommandSorting = defaultCommandSorting
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetOutput(t *testing.T) {
|
func TestSetOutput(t *testing.T) {
|
||||||
|
@ -1723,6 +1873,38 @@ func TestFlagErrorFunc(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFlagErrorFuncHelp(t *testing.T) {
|
||||||
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
|
c.PersistentFlags().Bool("help", false, "help for c")
|
||||||
|
c.SetFlagErrorFunc(func(_ *Command, err error) error {
|
||||||
|
return fmt.Errorf("wrap error: %w", err)
|
||||||
|
})
|
||||||
|
|
||||||
|
out, err := executeCommand(c, "--help")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("--help should not fail: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := `Usage:
|
||||||
|
c [flags]
|
||||||
|
|
||||||
|
Flags:
|
||||||
|
--help help for c
|
||||||
|
`
|
||||||
|
if out != expected {
|
||||||
|
t.Errorf("Expected: %v, got: %v", expected, out)
|
||||||
|
}
|
||||||
|
|
||||||
|
out, err = executeCommand(c, "-h")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("-h should not fail: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if out != expected {
|
||||||
|
t.Errorf("Expected: %v, got: %v", expected, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestSortedFlags checks,
|
// TestSortedFlags checks,
|
||||||
// if cmd.LocalFlags() is unsorted when cmd.Flags().SortFlags set to false.
|
// if cmd.LocalFlags() is unsorted when cmd.Flags().SortFlags set to false.
|
||||||
// Related to https://github.com/spf13/cobra/issues/404.
|
// Related to https://github.com/spf13/cobra/issues/404.
|
||||||
|
@ -2058,3 +2240,193 @@ func TestFParseErrWhitelistSiblingCommand(t *testing.T) {
|
||||||
}
|
}
|
||||||
checkStringContains(t, output, "unknown flag: --unknown")
|
checkStringContains(t, output, "unknown flag: --unknown")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetContext(t *testing.T) {
|
||||||
|
type key struct{}
|
||||||
|
val := "foobar"
|
||||||
|
root := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
key := cmd.Context().Value(key{})
|
||||||
|
got, ok := key.(string)
|
||||||
|
if !ok {
|
||||||
|
t.Error("key not found in context")
|
||||||
|
}
|
||||||
|
if got != val {
|
||||||
|
t.Errorf("Expected value: \n %v\nGot:\n %v\n", val, got)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx := context.WithValue(context.Background(), key{}, val)
|
||||||
|
root.SetContext(ctx)
|
||||||
|
err := root.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetContextPreRun(t *testing.T) {
|
||||||
|
type key struct{}
|
||||||
|
val := "barr"
|
||||||
|
root := &Command{
|
||||||
|
Use: "root",
|
||||||
|
PreRun: func(cmd *Command, args []string) {
|
||||||
|
ctx := context.WithValue(cmd.Context(), key{}, val)
|
||||||
|
cmd.SetContext(ctx)
|
||||||
|
},
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
val := cmd.Context().Value(key{})
|
||||||
|
got, ok := val.(string)
|
||||||
|
if !ok {
|
||||||
|
t.Error("key not found in context")
|
||||||
|
}
|
||||||
|
if got != val {
|
||||||
|
t.Errorf("Expected value: \n %v\nGot:\n %v\n", val, got)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err := root.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetContextPreRunOverwrite(t *testing.T) {
|
||||||
|
type key struct{}
|
||||||
|
val := "blah"
|
||||||
|
root := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
key := cmd.Context().Value(key{})
|
||||||
|
_, ok := key.(string)
|
||||||
|
if ok {
|
||||||
|
t.Error("key found in context when not expected")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctx := context.WithValue(context.Background(), key{}, val)
|
||||||
|
root.SetContext(ctx)
|
||||||
|
err := root.ExecuteContext(context.Background())
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSetContextPersistentPreRun(t *testing.T) {
|
||||||
|
type key struct{}
|
||||||
|
val := "barbar"
|
||||||
|
root := &Command{
|
||||||
|
Use: "root",
|
||||||
|
PersistentPreRun: func(cmd *Command, args []string) {
|
||||||
|
ctx := context.WithValue(cmd.Context(), key{}, val)
|
||||||
|
cmd.SetContext(ctx)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
child := &Command{
|
||||||
|
Use: "child",
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
key := cmd.Context().Value(key{})
|
||||||
|
got, ok := key.(string)
|
||||||
|
if !ok {
|
||||||
|
t.Error("key not found in context")
|
||||||
|
}
|
||||||
|
if got != val {
|
||||||
|
t.Errorf("Expected value: \n %v\nGot:\n %v\n", val, got)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
root.AddCommand(child)
|
||||||
|
root.SetArgs([]string{"child"})
|
||||||
|
err := root.Execute()
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const VersionFlag = "--version"
|
||||||
|
const HelpFlag = "--help"
|
||||||
|
|
||||||
|
func TestNoRootRunCommandExecutedWithVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Version: "1.0.0", Long: "Long description"}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringContains(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNoRootRunCommandExecutedWithoutVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Long: "Long description"}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringOmits(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelpCommandExecutedWithVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Version: "1.0.0", Long: "Long description", Run: emptyRun}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, "help")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringContains(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelpCommandExecutedWithoutVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Long: "Long description", Run: emptyRun}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, "help")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringOmits(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelpflagCommandExecutedWithVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Version: "1.0.0", Long: "Long description", Run: emptyRun}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, HelpFlag)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringContains(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestHelpflagCommandExecutedWithoutVersionSet(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Long: "Long description", Run: emptyRun}
|
||||||
|
rootCmd.AddCommand(&Command{Use: "child", Run: emptyRun})
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, HelpFlag)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
checkStringContains(t, output, rootCmd.Long)
|
||||||
|
checkStringContains(t, output, HelpFlag)
|
||||||
|
checkStringOmits(t, output, VersionFlag)
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,18 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
//go:build windows
|
||||||
// +build windows
|
// +build windows
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
167
completions.go
167
completions.go
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -93,6 +107,8 @@ type CompletionOptions struct {
|
||||||
// DisableDescriptions turns off all completion descriptions for shells
|
// DisableDescriptions turns off all completion descriptions for shells
|
||||||
// that support them
|
// that support them
|
||||||
DisableDescriptions bool
|
DisableDescriptions bool
|
||||||
|
// HiddenDefaultCmd makes the default 'completion' command hidden
|
||||||
|
HiddenDefaultCmd bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoFileCompletions can be used to disable file completion for commands that should
|
// NoFileCompletions can be used to disable file completion for commands that should
|
||||||
|
@ -101,6 +117,14 @@ func NoFileCompletions(cmd *Command, args []string, toComplete string) ([]string
|
||||||
return nil, ShellCompDirectiveNoFileComp
|
return nil, ShellCompDirectiveNoFileComp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FixedCompletions can be used to create a completion function which always
|
||||||
|
// returns the same results.
|
||||||
|
func FixedCompletions(choices []string, directive ShellCompDirective) func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return choices, directive
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// RegisterFlagCompletionFunc should be called to register a function to provide completion for a flag.
|
// RegisterFlagCompletionFunc should be called to register a function to provide completion for a flag.
|
||||||
func (c *Command) RegisterFlagCompletionFunc(flagName string, f func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)) error {
|
func (c *Command) RegisterFlagCompletionFunc(flagName string, f func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)) error {
|
||||||
flag := c.Flag(flagName)
|
flag := c.Flag(flagName)
|
||||||
|
@ -168,6 +192,12 @@ func (c *Command) initCompleteCmd(args []string) {
|
||||||
|
|
||||||
noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd)
|
noDescriptions := (cmd.CalledAs() == ShellCompNoDescRequestCmd)
|
||||||
for _, comp := range completions {
|
for _, comp := range completions {
|
||||||
|
if GetActiveHelpConfig(finalCmd) == activeHelpGlobalDisable {
|
||||||
|
// Remove all activeHelp entries in this case
|
||||||
|
if strings.HasPrefix(comp, activeHelpMarker) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
if noDescriptions {
|
if noDescriptions {
|
||||||
// Remove any description that may be included following a tab character.
|
// Remove any description that may be included following a tab character.
|
||||||
comp = strings.Split(comp, "\t")[0]
|
comp = strings.Split(comp, "\t")[0]
|
||||||
|
@ -226,7 +256,17 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
if c.Root().TraverseChildren {
|
if c.Root().TraverseChildren {
|
||||||
finalCmd, finalArgs, err = c.Root().Traverse(trimmedArgs)
|
finalCmd, finalArgs, err = c.Root().Traverse(trimmedArgs)
|
||||||
} else {
|
} else {
|
||||||
finalCmd, finalArgs, err = c.Root().Find(trimmedArgs)
|
// For Root commands that don't specify any value for their Args fields, when we call
|
||||||
|
// Find(), if those Root commands don't have any sub-commands, they will accept arguments.
|
||||||
|
// However, because we have added the __complete sub-command in the current code path, the
|
||||||
|
// call to Find() -> legacyArgs() will return an error if there are any arguments.
|
||||||
|
// To avoid this, we first remove the __complete command to get back to having no sub-commands.
|
||||||
|
rootCmd := c.Root()
|
||||||
|
if len(rootCmd.Commands()) == 1 {
|
||||||
|
rootCmd.RemoveCommand(c)
|
||||||
|
}
|
||||||
|
|
||||||
|
finalCmd, finalArgs, err = rootCmd.Find(trimmedArgs)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Unable to find the real command. E.g., <program> someInvalidCmd <TAB>
|
// Unable to find the real command. E.g., <program> someInvalidCmd <TAB>
|
||||||
|
@ -234,6 +274,12 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
}
|
}
|
||||||
finalCmd.ctx = c.ctx
|
finalCmd.ctx = c.ctx
|
||||||
|
|
||||||
|
// These flags are normally added when `execute()` is called on `finalCmd`,
|
||||||
|
// however, when doing completion, we don't call `finalCmd.execute()`.
|
||||||
|
// Let's add the --help and --version flag ourselves.
|
||||||
|
finalCmd.InitDefaultHelpFlag()
|
||||||
|
finalCmd.InitDefaultVersionFlag()
|
||||||
|
|
||||||
// Check if we are doing flag value completion before parsing the flags.
|
// Check if we are doing flag value completion before parsing the flags.
|
||||||
// This is important because if we are completing a flag value, we need to also
|
// This is important because if we are completing a flag value, we need to also
|
||||||
// remove the flag name argument from the list of finalArgs or else the parsing
|
// remove the flag name argument from the list of finalArgs or else the parsing
|
||||||
|
@ -266,6 +312,18 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Look for the --help or --version flags. If they are present,
|
||||||
|
// there should be no further completions.
|
||||||
|
if helpOrVersionFlagPresent(finalCmd) {
|
||||||
|
return finalCmd, []string{}, ShellCompDirectiveNoFileComp, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// We only remove the flags from the arguments if DisableFlagParsing is not set.
|
||||||
|
// This is important for commands which have requested to do their own flag completion.
|
||||||
|
if !finalCmd.DisableFlagParsing {
|
||||||
|
finalArgs = finalCmd.Flags().Args()
|
||||||
|
}
|
||||||
|
|
||||||
if flag != nil && flagCompletion {
|
if flag != nil && flagCompletion {
|
||||||
// Check if we are completing a flag value subject to annotations
|
// Check if we are completing a flag value subject to annotations
|
||||||
if validExts, present := flag.Annotations[BashCompFilenameExt]; present {
|
if validExts, present := flag.Annotations[BashCompFilenameExt]; present {
|
||||||
|
@ -290,12 +348,19 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var completions []string
|
||||||
|
var directive ShellCompDirective
|
||||||
|
|
||||||
|
// Enforce flag groups before doing flag completions
|
||||||
|
finalCmd.enforceFlagGroupsForCompletion()
|
||||||
|
|
||||||
|
// Note that we want to perform flagname completion even if finalCmd.DisableFlagParsing==true;
|
||||||
|
// doing this allows for completion of persistent flag names even for commands that disable flag parsing.
|
||||||
|
//
|
||||||
// When doing completion of a flag name, as soon as an argument starts with
|
// When doing completion of a flag name, as soon as an argument starts with
|
||||||
// a '-' we know it is a flag. We cannot use isFlagArg() here as it requires
|
// a '-' we know it is a flag. We cannot use isFlagArg() here as it requires
|
||||||
// the flag name to be complete
|
// the flag name to be complete
|
||||||
if flag == nil && len(toComplete) > 0 && toComplete[0] == '-' && !strings.Contains(toComplete, "=") && flagCompletion {
|
if flag == nil && len(toComplete) > 0 && toComplete[0] == '-' && !strings.Contains(toComplete, "=") && flagCompletion {
|
||||||
var completions []string
|
|
||||||
|
|
||||||
// First check for required flags
|
// First check for required flags
|
||||||
completions = completeRequireFlags(finalCmd, toComplete)
|
completions = completeRequireFlags(finalCmd, toComplete)
|
||||||
|
|
||||||
|
@ -322,23 +387,22 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
directive := ShellCompDirectiveNoFileComp
|
directive = ShellCompDirectiveNoFileComp
|
||||||
if len(completions) == 1 && strings.HasSuffix(completions[0], "=") {
|
if len(completions) == 1 && strings.HasSuffix(completions[0], "=") {
|
||||||
// If there is a single completion, the shell usually adds a space
|
// If there is a single completion, the shell usually adds a space
|
||||||
// after the completion. We don't want that if the flag ends with an =
|
// after the completion. We don't want that if the flag ends with an =
|
||||||
directive = ShellCompDirectiveNoSpace
|
directive = ShellCompDirectiveNoSpace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !finalCmd.DisableFlagParsing {
|
||||||
|
// If DisableFlagParsing==false, we have completed the flags as known by Cobra;
|
||||||
|
// we can return what we found.
|
||||||
|
// If DisableFlagParsing==true, Cobra may not be aware of all flags, so we
|
||||||
|
// let the logic continue to see if ValidArgsFunction needs to be called.
|
||||||
return finalCmd, completions, directive, nil
|
return finalCmd, completions, directive, nil
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// We only remove the flags from the arguments if DisableFlagParsing is not set.
|
directive = ShellCompDirectiveDefault
|
||||||
// This is important for commands which have requested to do their own flag completion.
|
|
||||||
if !finalCmd.DisableFlagParsing {
|
|
||||||
finalArgs = finalCmd.Flags().Args()
|
|
||||||
}
|
|
||||||
|
|
||||||
var completions []string
|
|
||||||
directive := ShellCompDirectiveDefault
|
|
||||||
if flag == nil {
|
if flag == nil {
|
||||||
foundLocalNonPersistentFlag := false
|
foundLocalNonPersistentFlag := false
|
||||||
// If TraverseChildren is true on the root command we don't check for
|
// If TraverseChildren is true on the root command we don't check for
|
||||||
|
@ -403,6 +467,7 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
// even if we already found sub-commands.
|
// even if we already found sub-commands.
|
||||||
// This is for commands that have subcommands but also specify a ValidArgsFunction.
|
// This is for commands that have subcommands but also specify a ValidArgsFunction.
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Find the completion function for the flag or command
|
// Find the completion function for the flag or command
|
||||||
var completionFn func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
|
var completionFn func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective)
|
||||||
|
@ -424,6 +489,18 @@ func (c *Command) getCompletions(args []string) (*Command, []string, ShellCompDi
|
||||||
return finalCmd, completions, directive, nil
|
return finalCmd, completions, directive, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func helpOrVersionFlagPresent(cmd *Command) bool {
|
||||||
|
if versionFlag := cmd.Flags().Lookup("version"); versionFlag != nil &&
|
||||||
|
len(versionFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && versionFlag.Changed {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if helpFlag := cmd.Flags().Lookup("help"); helpFlag != nil &&
|
||||||
|
len(helpFlag.Annotations[FlagSetByCobraAnnotation]) > 0 && helpFlag.Changed {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func getFlagNameCompletions(flag *pflag.Flag, toComplete string) []string {
|
func getFlagNameCompletions(flag *pflag.Flag, toComplete string) []string {
|
||||||
if nonCompletableFlag(flag) {
|
if nonCompletableFlag(flag) {
|
||||||
return []string{}
|
return []string{}
|
||||||
|
@ -589,39 +666,43 @@ func (c *Command) InitDefaultCompletionCmd() {
|
||||||
|
|
||||||
completionCmd := &Command{
|
completionCmd := &Command{
|
||||||
Use: compCmdName,
|
Use: compCmdName,
|
||||||
Short: "generate the autocompletion script for the specified shell",
|
Short: "Generate the autocompletion script for the specified shell",
|
||||||
Long: fmt.Sprintf(`
|
Long: fmt.Sprintf(`Generate the autocompletion script for %[1]s for the specified shell.
|
||||||
Generate the autocompletion script for %[1]s for the specified shell.
|
|
||||||
See each sub-command's help for details on how to use the generated script.
|
See each sub-command's help for details on how to use the generated script.
|
||||||
`, c.Root().Name()),
|
`, c.Root().Name()),
|
||||||
Args: NoArgs,
|
Args: NoArgs,
|
||||||
ValidArgsFunction: NoFileCompletions,
|
ValidArgsFunction: NoFileCompletions,
|
||||||
|
Hidden: c.CompletionOptions.HiddenDefaultCmd,
|
||||||
}
|
}
|
||||||
c.AddCommand(completionCmd)
|
c.AddCommand(completionCmd)
|
||||||
|
|
||||||
out := c.OutOrStdout()
|
out := c.OutOrStdout()
|
||||||
noDesc := c.CompletionOptions.DisableDescriptions
|
noDesc := c.CompletionOptions.DisableDescriptions
|
||||||
shortDesc := "generate the autocompletion script for %s"
|
shortDesc := "Generate the autocompletion script for %s"
|
||||||
bash := &Command{
|
bash := &Command{
|
||||||
Use: "bash",
|
Use: "bash",
|
||||||
Short: fmt.Sprintf(shortDesc, "bash"),
|
Short: fmt.Sprintf(shortDesc, "bash"),
|
||||||
Long: fmt.Sprintf(`
|
Long: fmt.Sprintf(`Generate the autocompletion script for the bash shell.
|
||||||
Generate the autocompletion script for the bash shell.
|
|
||||||
|
|
||||||
This script depends on the 'bash-completion' package.
|
This script depends on the 'bash-completion' package.
|
||||||
If it is not installed already, you can install it via your OS's package manager.
|
If it is not installed already, you can install it via your OS's package manager.
|
||||||
|
|
||||||
To load completions in your current shell session:
|
To load completions in your current shell session:
|
||||||
$ source <(%[1]s completion bash)
|
|
||||||
|
source <(%[1]s completion bash)
|
||||||
|
|
||||||
To load completions for every new session, execute once:
|
To load completions for every new session, execute once:
|
||||||
Linux:
|
|
||||||
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
|
#### Linux:
|
||||||
MacOS:
|
|
||||||
$ %[1]s completion bash > /usr/local/etc/bash_completion.d/%[1]s
|
%[1]s completion bash > /etc/bash_completion.d/%[1]s
|
||||||
|
|
||||||
|
#### macOS:
|
||||||
|
|
||||||
|
%[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
|
||||||
|
|
||||||
You will need to start a new shell for this setup to take effect.
|
You will need to start a new shell for this setup to take effect.
|
||||||
`, c.Root().Name()),
|
`, c.Root().Name()),
|
||||||
Args: NoArgs,
|
Args: NoArgs,
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
ValidArgsFunction: NoFileCompletions,
|
ValidArgsFunction: NoFileCompletions,
|
||||||
|
@ -636,19 +717,26 @@ You will need to start a new shell for this setup to take effect.
|
||||||
zsh := &Command{
|
zsh := &Command{
|
||||||
Use: "zsh",
|
Use: "zsh",
|
||||||
Short: fmt.Sprintf(shortDesc, "zsh"),
|
Short: fmt.Sprintf(shortDesc, "zsh"),
|
||||||
Long: fmt.Sprintf(`
|
Long: fmt.Sprintf(`Generate the autocompletion script for the zsh shell.
|
||||||
Generate the autocompletion script for the zsh shell.
|
|
||||||
|
|
||||||
If shell completion is not already enabled in your environment you will need
|
If shell completion is not already enabled in your environment you will need
|
||||||
to enable it. You can execute the following once:
|
to enable it. You can execute the following once:
|
||||||
|
|
||||||
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
echo "autoload -U compinit; compinit" >> ~/.zshrc
|
||||||
|
|
||||||
|
To load completions in your current shell session:
|
||||||
|
|
||||||
|
source <(%[1]s completion zsh); compdef _%[1]s %[1]s
|
||||||
|
|
||||||
To load completions for every new session, execute once:
|
To load completions for every new session, execute once:
|
||||||
# Linux:
|
|
||||||
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
|
#### Linux:
|
||||||
# macOS:
|
|
||||||
$ %[1]s completion zsh > /usr/local/share/zsh/site-functions/_%[1]s
|
%[1]s completion zsh > "${fpath[1]}/_%[1]s"
|
||||||
|
|
||||||
|
#### macOS:
|
||||||
|
|
||||||
|
%[1]s completion zsh > $(brew --prefix)/share/zsh/site-functions/_%[1]s
|
||||||
|
|
||||||
You will need to start a new shell for this setup to take effect.
|
You will need to start a new shell for this setup to take effect.
|
||||||
`, c.Root().Name()),
|
`, c.Root().Name()),
|
||||||
|
@ -668,14 +756,15 @@ You will need to start a new shell for this setup to take effect.
|
||||||
fish := &Command{
|
fish := &Command{
|
||||||
Use: "fish",
|
Use: "fish",
|
||||||
Short: fmt.Sprintf(shortDesc, "fish"),
|
Short: fmt.Sprintf(shortDesc, "fish"),
|
||||||
Long: fmt.Sprintf(`
|
Long: fmt.Sprintf(`Generate the autocompletion script for the fish shell.
|
||||||
Generate the autocompletion script for the fish shell.
|
|
||||||
|
|
||||||
To load completions in your current shell session:
|
To load completions in your current shell session:
|
||||||
$ %[1]s completion fish | source
|
|
||||||
|
%[1]s completion fish | source
|
||||||
|
|
||||||
To load completions for every new session, execute once:
|
To load completions for every new session, execute once:
|
||||||
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
|
|
||||||
|
%[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
|
||||||
|
|
||||||
You will need to start a new shell for this setup to take effect.
|
You will need to start a new shell for this setup to take effect.
|
||||||
`, c.Root().Name()),
|
`, c.Root().Name()),
|
||||||
|
@ -692,11 +781,11 @@ You will need to start a new shell for this setup to take effect.
|
||||||
powershell := &Command{
|
powershell := &Command{
|
||||||
Use: "powershell",
|
Use: "powershell",
|
||||||
Short: fmt.Sprintf(shortDesc, "powershell"),
|
Short: fmt.Sprintf(shortDesc, "powershell"),
|
||||||
Long: fmt.Sprintf(`
|
Long: fmt.Sprintf(`Generate the autocompletion script for powershell.
|
||||||
Generate the autocompletion script for powershell.
|
|
||||||
|
|
||||||
To load completions in your current shell session:
|
To load completions in your current shell session:
|
||||||
PS C:\> %[1]s completion powershell | Out-String | Invoke-Expression
|
|
||||||
|
%[1]s completion powershell | Out-String | Invoke-Expression
|
||||||
|
|
||||||
To load completions for every new session, add the output of the above command
|
To load completions for every new session, add the output of the above command
|
||||||
to your powershell profile.
|
to your powershell profile.
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -125,7 +139,7 @@ func TestCmdNameCompletionInGo(t *testing.T) {
|
||||||
|
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"aliased\tA command with aliases",
|
"aliased\tA command with aliases",
|
||||||
"completion\tgenerate the autocompletion script for the specified shell",
|
"completion\tGenerate the autocompletion script for the specified shell",
|
||||||
"firstChild\tFirst command",
|
"firstChild\tFirst command",
|
||||||
"help\tHelp about any command",
|
"help\tHelp about any command",
|
||||||
"secondChild",
|
"secondChild",
|
||||||
|
@ -480,6 +494,7 @@ func TestFlagNameCompletionInGo(t *testing.T) {
|
||||||
}
|
}
|
||||||
childCmd := &Command{
|
childCmd := &Command{
|
||||||
Use: "childCmd",
|
Use: "childCmd",
|
||||||
|
Version: "1.2.3",
|
||||||
Run: emptyRun,
|
Run: emptyRun,
|
||||||
}
|
}
|
||||||
rootCmd.AddCommand(childCmd)
|
rootCmd.AddCommand(childCmd)
|
||||||
|
@ -514,6 +529,8 @@ func TestFlagNameCompletionInGo(t *testing.T) {
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"--first",
|
"--first",
|
||||||
"-f",
|
"-f",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
"--second",
|
"--second",
|
||||||
"-s",
|
"-s",
|
||||||
":4",
|
":4",
|
||||||
|
@ -547,7 +564,11 @@ func TestFlagNameCompletionInGo(t *testing.T) {
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"--second",
|
"--second",
|
||||||
"-s",
|
"-s",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
"--subFlag",
|
"--subFlag",
|
||||||
|
"--version",
|
||||||
|
"-v",
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
@ -564,6 +585,7 @@ func TestFlagNameCompletionInGoWithDesc(t *testing.T) {
|
||||||
childCmd := &Command{
|
childCmd := &Command{
|
||||||
Use: "childCmd",
|
Use: "childCmd",
|
||||||
Short: "first command",
|
Short: "first command",
|
||||||
|
Version: "1.2.3",
|
||||||
Run: emptyRun,
|
Run: emptyRun,
|
||||||
}
|
}
|
||||||
rootCmd.AddCommand(childCmd)
|
rootCmd.AddCommand(childCmd)
|
||||||
|
@ -580,7 +602,7 @@ func TestFlagNameCompletionInGoWithDesc(t *testing.T) {
|
||||||
|
|
||||||
expected := strings.Join([]string{
|
expected := strings.Join([]string{
|
||||||
"childCmd\tfirst command",
|
"childCmd\tfirst command",
|
||||||
"completion\tgenerate the autocompletion script for the specified shell",
|
"completion\tGenerate the autocompletion script for the specified shell",
|
||||||
"help\tHelp about any command",
|
"help\tHelp about any command",
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
@ -598,6 +620,8 @@ func TestFlagNameCompletionInGoWithDesc(t *testing.T) {
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"--first\tfirst flag",
|
"--first\tfirst flag",
|
||||||
"-f\tfirst flag",
|
"-f\tfirst flag",
|
||||||
|
"--help\thelp for root",
|
||||||
|
"-h\thelp for root",
|
||||||
"--second\tsecond flag",
|
"--second\tsecond flag",
|
||||||
"-s\tsecond flag",
|
"-s\tsecond flag",
|
||||||
":4",
|
":4",
|
||||||
|
@ -631,7 +655,11 @@ func TestFlagNameCompletionInGoWithDesc(t *testing.T) {
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"--second\tsecond flag",
|
"--second\tsecond flag",
|
||||||
"-s\tsecond flag",
|
"-s\tsecond flag",
|
||||||
|
"--help\thelp for childCmd",
|
||||||
|
"-h\thelp for childCmd",
|
||||||
"--subFlag\tsub flag",
|
"--subFlag\tsub flag",
|
||||||
|
"--version\tversion for childCmd",
|
||||||
|
"-v\tversion for childCmd",
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
@ -674,6 +702,7 @@ func TestFlagNameCompletionRepeat(t *testing.T) {
|
||||||
expected := strings.Join([]string{
|
expected := strings.Join([]string{
|
||||||
"--array",
|
"--array",
|
||||||
"--bslice",
|
"--bslice",
|
||||||
|
"--help",
|
||||||
"--second",
|
"--second",
|
||||||
"--slice",
|
"--slice",
|
||||||
":4",
|
":4",
|
||||||
|
@ -695,6 +724,7 @@ func TestFlagNameCompletionRepeat(t *testing.T) {
|
||||||
expected = strings.Join([]string{
|
expected = strings.Join([]string{
|
||||||
"--array",
|
"--array",
|
||||||
"--bslice",
|
"--bslice",
|
||||||
|
"--help",
|
||||||
"--slice",
|
"--slice",
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
@ -717,6 +747,7 @@ func TestFlagNameCompletionRepeat(t *testing.T) {
|
||||||
"--array",
|
"--array",
|
||||||
"--bslice",
|
"--bslice",
|
||||||
"--first",
|
"--first",
|
||||||
|
"--help",
|
||||||
"--second",
|
"--second",
|
||||||
"--slice",
|
"--slice",
|
||||||
":4",
|
":4",
|
||||||
|
@ -742,6 +773,8 @@ func TestFlagNameCompletionRepeat(t *testing.T) {
|
||||||
"-b",
|
"-b",
|
||||||
"--first",
|
"--first",
|
||||||
"-f",
|
"-f",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
"--second",
|
"--second",
|
||||||
"-s",
|
"-s",
|
||||||
"--slice",
|
"--slice",
|
||||||
|
@ -1778,6 +1811,7 @@ func TestFlagCompletionWithNotInterspersedArgs(t *testing.T) {
|
||||||
|
|
||||||
expected := strings.Join([]string{
|
expected := strings.Join([]string{
|
||||||
"--bool\ttest bool flag",
|
"--bool\ttest bool flag",
|
||||||
|
"--help\thelp for child",
|
||||||
"--string\ttest string flag",
|
"--string\ttest string flag",
|
||||||
":4",
|
":4",
|
||||||
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
@ -2398,6 +2432,21 @@ func TestDefaultCompletionCmd(t *testing.T) {
|
||||||
rootCmd.CompletionOptions.DisableDescriptions = false
|
rootCmd.CompletionOptions.DisableDescriptions = false
|
||||||
// Remove completion command for the next test
|
// Remove completion command for the next test
|
||||||
removeCompCmd(rootCmd)
|
removeCompCmd(rootCmd)
|
||||||
|
|
||||||
|
// Test that the 'completion' command can be hidden
|
||||||
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||||
|
assertNoErr(t, rootCmd.Execute())
|
||||||
|
compCmd, _, err = rootCmd.Find([]string{compCmdName})
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
if compCmd.Hidden == false {
|
||||||
|
t.Error("Default 'completion' command should be hidden but it is not")
|
||||||
|
}
|
||||||
|
// Re-enable for next test
|
||||||
|
rootCmd.CompletionOptions.HiddenDefaultCmd = false
|
||||||
|
// Remove completion command for the next test
|
||||||
|
removeCompCmd(rootCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCompleteCompletion(t *testing.T) {
|
func TestCompleteCompletion(t *testing.T) {
|
||||||
|
@ -2543,3 +2592,526 @@ func TestMultipleShorthandFlagCompletion(t *testing.T) {
|
||||||
t.Errorf("expected: %q, got: %q", expected, output)
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCompleteWithDisableFlagParsing(t *testing.T) {
|
||||||
|
|
||||||
|
flagValidArgs := func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"--flag", "-f"}, ShellCompDirectiveNoFileComp
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "child",
|
||||||
|
Run: emptyRun,
|
||||||
|
DisableFlagParsing: true,
|
||||||
|
ValidArgsFunction: flagValidArgs,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().StringP("persistent", "p", "", "persistent flag")
|
||||||
|
childCmd.Flags().StringP("nonPersistent", "n", "", "non-persistent flag")
|
||||||
|
|
||||||
|
// Test that when DisableFlagParsing==true, ValidArgsFunction is called to complete flag names,
|
||||||
|
// after Cobra tried to complete the flags it knows about.
|
||||||
|
childCmd.DisableFlagParsing = true
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "-")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"--persistent",
|
||||||
|
"-p",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--nonPersistent",
|
||||||
|
"-n",
|
||||||
|
"--flag",
|
||||||
|
"-f",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that when DisableFlagParsing==false, Cobra completes the flags itself and ValidArgsFunction is not called
|
||||||
|
childCmd.DisableFlagParsing = false
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "-")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cobra was not told of any flags, so it returns nothing
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
"--persistent",
|
||||||
|
"-p",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--nonPersistent",
|
||||||
|
"-n",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompleteWithRootAndLegacyArgs(t *testing.T) {
|
||||||
|
// Test a lonely root command which uses legacyArgs(). In such a case, the root
|
||||||
|
// command should accept any number of arguments and completion should behave accordingly.
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Args: nil, // Args must be nil to trigger the legacyArgs() function
|
||||||
|
Run: emptyRun,
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"arg1", "arg2"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the first arg is completed
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"arg1",
|
||||||
|
"arg2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure the completion of arguments continues
|
||||||
|
output, err = executeCommand(rootCmd, ShellCompNoDescRequestCmd, "arg1", "")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected = strings.Join([]string{
|
||||||
|
"arg1",
|
||||||
|
"arg2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFixedCompletions(t *testing.T) {
|
||||||
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
|
choices := []string{"apple", "banana", "orange"}
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "child",
|
||||||
|
ValidArgsFunction: FixedCompletions(choices, ShellCompDirectiveNoFileComp),
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
output, err := executeCommand(rootCmd, ShellCompNoDescRequestCmd, "child", "a")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Unexpected error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expected := strings.Join([]string{
|
||||||
|
"apple",
|
||||||
|
"banana",
|
||||||
|
"orange",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n")
|
||||||
|
|
||||||
|
if output != expected {
|
||||||
|
t.Errorf("expected: %q, got: %q", expected, output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompletionForGroupedFlags(t *testing.T) {
|
||||||
|
getCmd := func() *Command {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "child",
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"subArg"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().Int("ingroup1", -1, "ingroup1")
|
||||||
|
rootCmd.PersistentFlags().String("ingroup2", "", "ingroup2")
|
||||||
|
|
||||||
|
childCmd.Flags().Bool("ingroup3", false, "ingroup3")
|
||||||
|
childCmd.Flags().Bool("nogroup", false, "nogroup")
|
||||||
|
|
||||||
|
// Add flags to a group
|
||||||
|
childCmd.MarkFlagsRequiredTogether("ingroup1", "ingroup2", "ingroup3")
|
||||||
|
|
||||||
|
return rootCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each test case uses a unique command from the function above.
|
||||||
|
testcases := []struct {
|
||||||
|
desc string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "flags in group not suggested without - prefix",
|
||||||
|
args: []string{"child", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"subArg",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "flags in group suggested with - prefix",
|
||||||
|
args: []string{"child", "-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--ingroup1",
|
||||||
|
"--ingroup2",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--ingroup3",
|
||||||
|
"--nogroup",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "when flag in group present, other flags in group suggested even without - prefix",
|
||||||
|
args: []string{"child", "--ingroup2", "value", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--ingroup1",
|
||||||
|
"--ingroup3",
|
||||||
|
"subArg",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "when all flags in group present, flags not suggested without - prefix",
|
||||||
|
args: []string{"child", "--ingroup1", "8", "--ingroup2", "value2", "--ingroup3", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"subArg",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "group ignored if some flags not applicable",
|
||||||
|
args: []string{"--ingroup2", "value", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"child",
|
||||||
|
"completion",
|
||||||
|
"help",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testcases {
|
||||||
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
c := getCmd()
|
||||||
|
args := []string{ShellCompNoDescRequestCmd}
|
||||||
|
args = append(args, tc.args...)
|
||||||
|
output, err := executeCommand(c, args...)
|
||||||
|
switch {
|
||||||
|
case err == nil && output != tc.expectedOutput:
|
||||||
|
t.Errorf("expected: %q, got: %q", tc.expectedOutput, output)
|
||||||
|
case err != nil:
|
||||||
|
t.Errorf("Unexpected error %q", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompletionForMutuallyExclusiveFlags(t *testing.T) {
|
||||||
|
getCmd := func() *Command {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "child",
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"subArg"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(childCmd)
|
||||||
|
|
||||||
|
rootCmd.PersistentFlags().IntSlice("ingroup1", []int{1}, "ingroup1")
|
||||||
|
rootCmd.PersistentFlags().String("ingroup2", "", "ingroup2")
|
||||||
|
|
||||||
|
childCmd.Flags().Bool("ingroup3", false, "ingroup3")
|
||||||
|
childCmd.Flags().Bool("nogroup", false, "nogroup")
|
||||||
|
|
||||||
|
// Add flags to a group
|
||||||
|
childCmd.MarkFlagsMutuallyExclusive("ingroup1", "ingroup2", "ingroup3")
|
||||||
|
|
||||||
|
return rootCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each test case uses a unique command from the function above.
|
||||||
|
testcases := []struct {
|
||||||
|
desc string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "flags in mutually exclusive group not suggested without the - prefix",
|
||||||
|
args: []string{"child", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"subArg",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "flags in mutually exclusive group suggested with the - prefix",
|
||||||
|
args: []string{"child", "-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--ingroup1",
|
||||||
|
"--ingroup2",
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--ingroup3",
|
||||||
|
"--nogroup",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "when flag in mutually exclusive group present, other flags in group not suggested even with the - prefix",
|
||||||
|
args: []string{"child", "--ingroup1", "8", "-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--ingroup1", // Should be suggested again since it is a slice
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--nogroup",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "group ignored if some flags not applicable",
|
||||||
|
args: []string{"--ingroup1", "8", "-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--ingroup1",
|
||||||
|
"--ingroup2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testcases {
|
||||||
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
c := getCmd()
|
||||||
|
args := []string{ShellCompNoDescRequestCmd}
|
||||||
|
args = append(args, tc.args...)
|
||||||
|
output, err := executeCommand(c, args...)
|
||||||
|
switch {
|
||||||
|
case err == nil && output != tc.expectedOutput:
|
||||||
|
t.Errorf("expected: %q, got: %q", tc.expectedOutput, output)
|
||||||
|
case err != nil:
|
||||||
|
t.Errorf("Unexpected error %q", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCompletionCobraFlags(t *testing.T) {
|
||||||
|
getCmd := func() *Command {
|
||||||
|
rootCmd := &Command{
|
||||||
|
Use: "root",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
childCmd := &Command{
|
||||||
|
Use: "child",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Run: emptyRun,
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"extra"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
childCmd2 := &Command{
|
||||||
|
Use: "child2",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Run: emptyRun,
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"extra2"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
childCmd3 := &Command{
|
||||||
|
Use: "child3",
|
||||||
|
Version: "1.1.1",
|
||||||
|
Run: emptyRun,
|
||||||
|
ValidArgsFunction: func(cmd *Command, args []string, toComplete string) ([]string, ShellCompDirective) {
|
||||||
|
return []string{"extra3"}, ShellCompDirectiveNoFileComp
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
rootCmd.AddCommand(childCmd, childCmd2, childCmd3)
|
||||||
|
|
||||||
|
_ = childCmd.Flags().Bool("bool", false, "A bool flag")
|
||||||
|
_ = childCmd.MarkFlagRequired("bool")
|
||||||
|
|
||||||
|
// Have a command that adds its own help and version flag
|
||||||
|
_ = childCmd2.Flags().BoolP("help", "h", false, "My own help")
|
||||||
|
_ = childCmd2.Flags().BoolP("version", "v", false, "My own version")
|
||||||
|
|
||||||
|
// Have a command that only adds its own -v flag
|
||||||
|
_ = childCmd3.Flags().BoolP("verbose", "v", false, "Not a version flag")
|
||||||
|
|
||||||
|
return rootCmd
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each test case uses a unique command from the function above.
|
||||||
|
testcases := []struct {
|
||||||
|
desc string
|
||||||
|
args []string
|
||||||
|
expectedOutput string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "completion of help and version flags",
|
||||||
|
args: []string{"-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"--help",
|
||||||
|
"-h",
|
||||||
|
"--version",
|
||||||
|
"-v",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after --help flag",
|
||||||
|
args: []string{"--help", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after -h flag",
|
||||||
|
args: []string{"-h", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after --version flag",
|
||||||
|
args: []string{"--version", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after -v flag",
|
||||||
|
args: []string{"-v", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after --help flag even with other completions",
|
||||||
|
args: []string{"child", "--help", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after -h flag even with other completions",
|
||||||
|
args: []string{"child", "-h", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after --version flag even with other completions",
|
||||||
|
args: []string{"child", "--version", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after -v flag even with other completions",
|
||||||
|
args: []string{"child", "-v", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "no completion after -v flag even with other flag completions",
|
||||||
|
args: []string{"child", "-v", "-"},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after --help flag when created by program",
|
||||||
|
args: []string{"child2", "--help", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"extra2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after -h flag when created by program",
|
||||||
|
args: []string{"child2", "-h", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"extra2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after --version flag when created by program",
|
||||||
|
args: []string{"child2", "--version", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"extra2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after -v flag when created by program",
|
||||||
|
args: []string{"child2", "-v", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"extra2",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after --version when only -v flag was created by program",
|
||||||
|
args: []string{"child3", "--version", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "completion after -v flag when only -v flag was created by program",
|
||||||
|
args: []string{"child3", "-v", ""},
|
||||||
|
expectedOutput: strings.Join([]string{
|
||||||
|
"extra3",
|
||||||
|
":4",
|
||||||
|
"Completion ended with directive: ShellCompDirectiveNoFileComp", ""}, "\n"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testcases {
|
||||||
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
c := getCmd()
|
||||||
|
args := []string{ShellCompNoDescRequestCmd}
|
||||||
|
args = append(args, tc.args...)
|
||||||
|
output, err := executeCommand(c, args...)
|
||||||
|
switch {
|
||||||
|
case err == nil && output != tc.expectedOutput:
|
||||||
|
t.Errorf("expected: %q, got: %q", tc.expectedOutput, output)
|
||||||
|
case err != nil:
|
||||||
|
t.Errorf("Unexpected error %q", err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright 2015 Red Hat Inc. All rights reserved.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -66,7 +67,7 @@ func GenManTreeFromOpts(cmd *cobra.Command, opts GenManTreeOptions) error {
|
||||||
if opts.CommandSeparator != "" {
|
if opts.CommandSeparator != "" {
|
||||||
separator = opts.CommandSeparator
|
separator = opts.CommandSeparator
|
||||||
}
|
}
|
||||||
basename := strings.Replace(cmd.CommandPath(), " ", separator, -1)
|
basename := strings.ReplaceAll(cmd.CommandPath(), " ", separator)
|
||||||
filename := filepath.Join(opts.Path, basename+"."+section)
|
filename := filepath.Join(opts.Path, basename+"."+section)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -116,7 +117,7 @@ func GenMan(cmd *cobra.Command, header *GenManHeader, w io.Writer) error {
|
||||||
|
|
||||||
func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
|
func fillHeader(header *GenManHeader, name string, disableAutoGen bool) error {
|
||||||
if header.Title == "" {
|
if header.Title == "" {
|
||||||
header.Title = strings.ToUpper(strings.Replace(name, " ", "\\-", -1))
|
header.Title = strings.ToUpper(strings.ReplaceAll(name, " ", "\\-"))
|
||||||
}
|
}
|
||||||
if header.Section == "" {
|
if header.Section == "" {
|
||||||
header.Section = "1"
|
header.Section = "1"
|
||||||
|
@ -203,7 +204,7 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
|
||||||
cmd.InitDefaultHelpFlag()
|
cmd.InitDefaultHelpFlag()
|
||||||
|
|
||||||
// something like `rootcmd-subcmd1-subcmd2`
|
// something like `rootcmd-subcmd1-subcmd2`
|
||||||
dashCommandName := strings.Replace(cmd.CommandPath(), " ", "-", -1)
|
dashCommandName := strings.ReplaceAll(cmd.CommandPath(), " ", "-")
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
|
@ -218,7 +219,7 @@ func genMan(cmd *cobra.Command, header *GenManHeader) []byte {
|
||||||
seealsos := make([]string, 0)
|
seealsos := make([]string, 0)
|
||||||
if cmd.HasParent() {
|
if cmd.HasParent() {
|
||||||
parentPath := cmd.Parent().CommandPath()
|
parentPath := cmd.Parent().CommandPath()
|
||||||
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
|
dashParentPath := strings.ReplaceAll(parentPath, " ", "-")
|
||||||
seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
|
seealso := fmt.Sprintf("**%s(%s)**", dashParentPath, header.Section)
|
||||||
seealsos = append(seealsos, seealso)
|
seealsos = append(seealsos, seealso)
|
||||||
cmd.VisitParents(func(c *cobra.Command) {
|
cmd.VisitParents(func(c *cobra.Command) {
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -20,7 +34,7 @@ func assertNoErr(t *testing.T, e error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func translate(in string) string {
|
func translate(in string) string {
|
||||||
return strings.Replace(in, "-", "\\-", -1)
|
return strings.ReplaceAll(in, "-", "\\-")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenManDoc(t *testing.T) {
|
func TestGenManDoc(t *testing.T) {
|
||||||
|
@ -38,7 +52,7 @@ func TestGenManDoc(t *testing.T) {
|
||||||
|
|
||||||
// Make sure parent has - in CommandPath() in SEE ALSO:
|
// Make sure parent has - in CommandPath() in SEE ALSO:
|
||||||
parentPath := echoCmd.Parent().CommandPath()
|
parentPath := echoCmd.Parent().CommandPath()
|
||||||
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
|
dashParentPath := strings.ReplaceAll(parentPath, " ", "-")
|
||||||
expected := translate(dashParentPath)
|
expected := translate(dashParentPath)
|
||||||
expected = expected + "(" + header.Section + ")"
|
expected = expected + "(" + header.Section + ")"
|
||||||
checkStringContains(t, output, expected)
|
checkStringContains(t, output, expected)
|
||||||
|
@ -73,7 +87,7 @@ func TestGenManNoHiddenParents(t *testing.T) {
|
||||||
|
|
||||||
// Make sure parent has - in CommandPath() in SEE ALSO:
|
// Make sure parent has - in CommandPath() in SEE ALSO:
|
||||||
parentPath := echoCmd.Parent().CommandPath()
|
parentPath := echoCmd.Parent().CommandPath()
|
||||||
dashParentPath := strings.Replace(parentPath, " ", "-", -1)
|
dashParentPath := strings.ReplaceAll(parentPath, " ", "-")
|
||||||
expected := translate(dashParentPath)
|
expected := translate(dashParentPath)
|
||||||
expected = expected + "(" + header.Section + ")"
|
expected = expected + "(" + header.Section + ")"
|
||||||
checkStringContains(t, output, expected)
|
checkStringContains(t, output, expected)
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc_test
|
package doc_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//Copyright 2015 Red Hat Inc. All rights reserved.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -83,7 +84,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
|
||||||
parent := cmd.Parent()
|
parent := cmd.Parent()
|
||||||
pname := parent.CommandPath()
|
pname := parent.CommandPath()
|
||||||
link := pname + ".md"
|
link := pname + ".md"
|
||||||
link = strings.Replace(link, " ", "_", -1)
|
link = strings.ReplaceAll(link, " ", "_")
|
||||||
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))
|
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))
|
||||||
cmd.VisitParents(func(c *cobra.Command) {
|
cmd.VisitParents(func(c *cobra.Command) {
|
||||||
if c.DisableAutoGenTag {
|
if c.DisableAutoGenTag {
|
||||||
|
@ -101,7 +102,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
|
||||||
}
|
}
|
||||||
cname := name + " " + child.Name()
|
cname := name + " " + child.Name()
|
||||||
link := cname + ".md"
|
link := cname + ".md"
|
||||||
link = strings.Replace(link, " ", "_", -1)
|
link = strings.ReplaceAll(link, " ", "_")
|
||||||
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short))
|
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short))
|
||||||
}
|
}
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
|
@ -137,7 +138,7 @@ func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
|
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".md"
|
||||||
filename := filepath.Join(dir, basename)
|
filename := filepath.Join(dir, basename)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -85,7 +85,7 @@ func GenMarkdownCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/):
|
The `filePrepender` will prepend the return value given the full filepath to the rendered Markdown file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/):
|
||||||
|
|
||||||
```go
|
```go
|
||||||
const fmTemplate = `---
|
const fmTemplate = `---
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
//Copyright 2015 Red Hat Inc. All rights reserved.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -70,7 +71,7 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
|
||||||
if len(long) == 0 {
|
if len(long) == 0 {
|
||||||
long = short
|
long = short
|
||||||
}
|
}
|
||||||
ref := strings.Replace(name, " ", "_", -1)
|
ref := strings.ReplaceAll(name, " ", "_")
|
||||||
|
|
||||||
buf.WriteString(".. _" + ref + ":\n\n")
|
buf.WriteString(".. _" + ref + ":\n\n")
|
||||||
buf.WriteString(name + "\n")
|
buf.WriteString(name + "\n")
|
||||||
|
@ -99,7 +100,7 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
|
||||||
if cmd.HasParent() {
|
if cmd.HasParent() {
|
||||||
parent := cmd.Parent()
|
parent := cmd.Parent()
|
||||||
pname := parent.CommandPath()
|
pname := parent.CommandPath()
|
||||||
ref = strings.Replace(pname, " ", "_", -1)
|
ref = strings.ReplaceAll(pname, " ", "_")
|
||||||
buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(pname, ref), parent.Short))
|
buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(pname, ref), parent.Short))
|
||||||
cmd.VisitParents(func(c *cobra.Command) {
|
cmd.VisitParents(func(c *cobra.Command) {
|
||||||
if c.DisableAutoGenTag {
|
if c.DisableAutoGenTag {
|
||||||
|
@ -116,7 +117,7 @@ func GenReSTCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string, str
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
cname := name + " " + child.Name()
|
cname := name + " " + child.Name()
|
||||||
ref = strings.Replace(cname, " ", "_", -1)
|
ref = strings.ReplaceAll(cname, " ", "_")
|
||||||
buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(cname, ref), child.Short))
|
buf.WriteString(fmt.Sprintf("* %s \t - %s\n", linkHandler(cname, ref), child.Short))
|
||||||
}
|
}
|
||||||
buf.WriteString("\n")
|
buf.WriteString("\n")
|
||||||
|
@ -151,7 +152,7 @@ func GenReSTTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".rst"
|
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".rst"
|
||||||
filename := filepath.Join(dir, basename)
|
filename := filepath.Join(dir, basename)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -85,7 +85,7 @@ func GenReSTCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string, str
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `filePrepender` will prepend the return value given the full filepath to the rendered ReST file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/):
|
The `filePrepender` will prepend the return value given the full filepath to the rendered ReST file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/):
|
||||||
|
|
||||||
```go
|
```go
|
||||||
const fmTemplate = `---
|
const fmTemplate = `---
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright 2015 Red Hat Inc. All rights reserved.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright 2016 French Ben. All rights reserved.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -23,7 +24,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
type cmdOption struct {
|
type cmdOption struct {
|
||||||
|
@ -66,7 +67,7 @@ func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandle
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".yaml"
|
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".yaml"
|
||||||
filename := filepath.Join(dir, basename)
|
filename := filepath.Join(dir, basename)
|
||||||
f, err := os.Create(filename)
|
f, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -128,7 +129,7 @@ func GenYamlCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string) str
|
||||||
if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
|
if !child.IsAvailableCommand() || child.IsAdditionalHelpTopicCommand() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
result = append(result, child.Name()+" - "+child.Short)
|
result = append(result, child.CommandPath()+" - "+child.Short)
|
||||||
}
|
}
|
||||||
yamlDoc.SeeAlso = result
|
yamlDoc.SeeAlso = result
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@ func GenYamlCustom(cmd *Command, out *bytes.Buffer, linkHandler func(string) str
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The `filePrepender` will prepend the return value given the full filepath to the rendered Yaml file. A common use case is to add front matter to use the generated documentation with [Hugo](http://gohugo.io/):
|
The `filePrepender` will prepend the return value given the full filepath to the rendered Yaml file. A common use case is to add front matter to use the generated documentation with [Hugo](https://gohugo.io/):
|
||||||
|
|
||||||
```go
|
```go
|
||||||
const fmTemplate = `---
|
const fmTemplate = `---
|
||||||
|
|
|
@ -1,7 +1,22 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package doc
|
package doc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -24,6 +39,7 @@ func TestGenYamlDoc(t *testing.T) {
|
||||||
checkStringContains(t, output, "rootflag")
|
checkStringContains(t, output, "rootflag")
|
||||||
checkStringContains(t, output, rootCmd.Short)
|
checkStringContains(t, output, rootCmd.Short)
|
||||||
checkStringContains(t, output, echoSubCmd.Short)
|
checkStringContains(t, output, echoSubCmd.Short)
|
||||||
|
checkStringContains(t, output, fmt.Sprintf("- %s - %s", echoSubCmd.CommandPath(), echoSubCmd.Short))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGenYamlNoTag(t *testing.T) {
|
func TestGenYamlNoTag(t *testing.T) {
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,8 +25,8 @@ import (
|
||||||
func genFishComp(buf io.StringWriter, name string, includeDesc bool) {
|
func genFishComp(buf io.StringWriter, name string, includeDesc bool) {
|
||||||
// Variables should not contain a '-' or ':' character
|
// Variables should not contain a '-' or ':' character
|
||||||
nameForVar := name
|
nameForVar := name
|
||||||
nameForVar = strings.Replace(nameForVar, "-", "_", -1)
|
nameForVar = strings.ReplaceAll(nameForVar, "-", "_")
|
||||||
nameForVar = strings.Replace(nameForVar, ":", "_", -1)
|
nameForVar = strings.ReplaceAll(nameForVar, ":", "_")
|
||||||
|
|
||||||
compCmd := ShellCompRequestCmd
|
compCmd := ShellCompRequestCmd
|
||||||
if !includeDesc {
|
if !includeDesc {
|
||||||
|
@ -38,7 +52,8 @@ function __%[1]s_perform_completion
|
||||||
__%[1]s_debug "args: $args"
|
__%[1]s_debug "args: $args"
|
||||||
__%[1]s_debug "last arg: $lastArg"
|
__%[1]s_debug "last arg: $lastArg"
|
||||||
|
|
||||||
set -l requestComp "$args[1] %[3]s $args[2..-1] $lastArg"
|
# Disable ActiveHelp which is not supported for fish shell
|
||||||
|
set -l requestComp "%[9]s=0 $args[1] %[3]s $args[2..-1] $lastArg"
|
||||||
|
|
||||||
__%[1]s_debug "Calling $requestComp"
|
__%[1]s_debug "Calling $requestComp"
|
||||||
set -l results (eval $requestComp 2> /dev/null)
|
set -l results (eval $requestComp 2> /dev/null)
|
||||||
|
@ -196,7 +211,7 @@ complete -c %[2]s -n '__%[1]s_prepare_completions' -f -a '$__%[1]s_comp_results'
|
||||||
|
|
||||||
`, nameForVar, name, compCmd,
|
`, nameForVar, name, compCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenFishCompletion generates fish completion file and writes to the passed writer.
|
// GenFishCompletion generates fish completion file and writes to the passed writer.
|
||||||
|
|
|
@ -1,7 +1,24 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -67,3 +84,69 @@ func TestProgWithColon(t *testing.T) {
|
||||||
check(t, output, "-c root:colon")
|
check(t, output, "-c root:colon")
|
||||||
checkOmit(t, output, "-c root_colon")
|
checkOmit(t, output, "-c root_colon")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFishCompletionNoActiveHelp(t *testing.T) {
|
||||||
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
assertNoErr(t, c.GenFishCompletion(buf, true))
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
// check that active help is being disabled
|
||||||
|
activeHelpVar := activeHelpEnvVar(c.Name())
|
||||||
|
check(t, output, fmt.Sprintf("%s=0", activeHelpVar))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGenFishCompletionFile(t *testing.T) {
|
||||||
|
err := os.Mkdir("./tmp", 0755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll("./tmp")
|
||||||
|
|
||||||
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
|
child := &Command{
|
||||||
|
Use: "child",
|
||||||
|
ValidArgsFunction: validArgsFunc,
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(child)
|
||||||
|
|
||||||
|
assertNoErr(t, rootCmd.GenFishCompletionFile("./tmp/test", false))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFailGenFishCompletionFile(t *testing.T) {
|
||||||
|
err := os.Mkdir("./tmp", 0755)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
defer os.RemoveAll("./tmp")
|
||||||
|
|
||||||
|
f, _ := os.OpenFile("./tmp/test", os.O_CREATE, 0400)
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
rootCmd := &Command{Use: "root", Args: NoArgs, Run: emptyRun}
|
||||||
|
child := &Command{
|
||||||
|
Use: "child",
|
||||||
|
ValidArgsFunction: validArgsFunc,
|
||||||
|
Run: emptyRun,
|
||||||
|
}
|
||||||
|
rootCmd.AddCommand(child)
|
||||||
|
|
||||||
|
got := rootCmd.GenFishCompletionFile("./tmp/test", false)
|
||||||
|
if got == nil {
|
||||||
|
t.Error("should raise permission denied error")
|
||||||
|
}
|
||||||
|
|
||||||
|
if os.Getenv("MSYSTEM") == "MINGW64" {
|
||||||
|
if got.Error() != "open ./tmp/test: Access is denied." {
|
||||||
|
t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: Access is denied.")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if got.Error() != "open ./tmp/test: permission denied" {
|
||||||
|
t.Errorf("got: %s, want: %s", got.Error(), "open ./tmp/test: permission denied")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
224
flag_groups.go
Normal file
224
flag_groups.go
Normal file
|
@ -0,0 +1,224 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
flag "github.com/spf13/pflag"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
requiredAsGroup = "cobra_annotation_required_if_others_set"
|
||||||
|
mutuallyExclusive = "cobra_annotation_mutually_exclusive"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MarkFlagsRequiredTogether marks the given flags with annotations so that Cobra errors
|
||||||
|
// if the command is invoked with a subset (but not all) of the given flags.
|
||||||
|
func (c *Command) MarkFlagsRequiredTogether(flagNames ...string) {
|
||||||
|
c.mergePersistentFlags()
|
||||||
|
for _, v := range flagNames {
|
||||||
|
f := c.Flags().Lookup(v)
|
||||||
|
if f == nil {
|
||||||
|
panic(fmt.Sprintf("Failed to find flag %q and mark it as being required in a flag group", v))
|
||||||
|
}
|
||||||
|
if err := c.Flags().SetAnnotation(v, requiredAsGroup, append(f.Annotations[requiredAsGroup], strings.Join(flagNames, " "))); err != nil {
|
||||||
|
// Only errs if the flag isn't found.
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MarkFlagsMutuallyExclusive marks the given flags with annotations so that Cobra errors
|
||||||
|
// if the command is invoked with more than one flag from the given set of flags.
|
||||||
|
func (c *Command) MarkFlagsMutuallyExclusive(flagNames ...string) {
|
||||||
|
c.mergePersistentFlags()
|
||||||
|
for _, v := range flagNames {
|
||||||
|
f := c.Flags().Lookup(v)
|
||||||
|
if f == nil {
|
||||||
|
panic(fmt.Sprintf("Failed to find flag %q and mark it as being in a mutually exclusive flag group", v))
|
||||||
|
}
|
||||||
|
// Each time this is called is a single new entry; this allows it to be a member of multiple groups if needed.
|
||||||
|
if err := c.Flags().SetAnnotation(v, mutuallyExclusive, append(f.Annotations[mutuallyExclusive], strings.Join(flagNames, " "))); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidateFlagGroups validates the mutuallyExclusive/requiredAsGroup logic and returns the
|
||||||
|
// first error encountered.
|
||||||
|
func (c *Command) ValidateFlagGroups() error {
|
||||||
|
if c.DisableFlagParsing {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := c.Flags()
|
||||||
|
|
||||||
|
// groupStatus format is the list of flags as a unique ID,
|
||||||
|
// then a map of each flag name and whether it is set or not.
|
||||||
|
groupStatus := map[string]map[string]bool{}
|
||||||
|
mutuallyExclusiveGroupStatus := map[string]map[string]bool{}
|
||||||
|
flags.VisitAll(func(pflag *flag.Flag) {
|
||||||
|
processFlagForGroupAnnotation(flags, pflag, requiredAsGroup, groupStatus)
|
||||||
|
processFlagForGroupAnnotation(flags, pflag, mutuallyExclusive, mutuallyExclusiveGroupStatus)
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := validateRequiredFlagGroups(groupStatus); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := validateExclusiveFlagGroups(mutuallyExclusiveGroupStatus); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func hasAllFlags(fs *flag.FlagSet, flagnames ...string) bool {
|
||||||
|
for _, fname := range flagnames {
|
||||||
|
f := fs.Lookup(fname)
|
||||||
|
if f == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func processFlagForGroupAnnotation(flags *flag.FlagSet, pflag *flag.Flag, annotation string, groupStatus map[string]map[string]bool) {
|
||||||
|
groupInfo, found := pflag.Annotations[annotation]
|
||||||
|
if found {
|
||||||
|
for _, group := range groupInfo {
|
||||||
|
if groupStatus[group] == nil {
|
||||||
|
flagnames := strings.Split(group, " ")
|
||||||
|
|
||||||
|
// Only consider this flag group at all if all the flags are defined.
|
||||||
|
if !hasAllFlags(flags, flagnames...) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
groupStatus[group] = map[string]bool{}
|
||||||
|
for _, name := range flagnames {
|
||||||
|
groupStatus[group][name] = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
groupStatus[group][pflag.Name] = pflag.Changed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateRequiredFlagGroups(data map[string]map[string]bool) error {
|
||||||
|
keys := sortedKeys(data)
|
||||||
|
for _, flagList := range keys {
|
||||||
|
flagnameAndStatus := data[flagList]
|
||||||
|
|
||||||
|
unset := []string{}
|
||||||
|
for flagname, isSet := range flagnameAndStatus {
|
||||||
|
if !isSet {
|
||||||
|
unset = append(unset, flagname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(unset) == len(flagnameAndStatus) || len(unset) == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort values, so they can be tested/scripted against consistently.
|
||||||
|
sort.Strings(unset)
|
||||||
|
return fmt.Errorf("if any flags in the group [%v] are set they must all be set; missing %v", flagList, unset)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func validateExclusiveFlagGroups(data map[string]map[string]bool) error {
|
||||||
|
keys := sortedKeys(data)
|
||||||
|
for _, flagList := range keys {
|
||||||
|
flagnameAndStatus := data[flagList]
|
||||||
|
var set []string
|
||||||
|
for flagname, isSet := range flagnameAndStatus {
|
||||||
|
if isSet {
|
||||||
|
set = append(set, flagname)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(set) == 0 || len(set) == 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort values, so they can be tested/scripted against consistently.
|
||||||
|
sort.Strings(set)
|
||||||
|
return fmt.Errorf("if any flags in the group [%v] are set none of the others can be; %v were all set", flagList, set)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func sortedKeys(m map[string]map[string]bool) []string {
|
||||||
|
keys := make([]string, len(m))
|
||||||
|
i := 0
|
||||||
|
for k := range m {
|
||||||
|
keys[i] = k
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
return keys
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforceFlagGroupsForCompletion will do the following:
|
||||||
|
// - when a flag in a group is present, other flags in the group will be marked required
|
||||||
|
// - when a flag in a mutually exclusive group is present, other flags in the group will be marked as hidden
|
||||||
|
// This allows the standard completion logic to behave appropriately for flag groups
|
||||||
|
func (c *Command) enforceFlagGroupsForCompletion() {
|
||||||
|
if c.DisableFlagParsing {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
flags := c.Flags()
|
||||||
|
groupStatus := map[string]map[string]bool{}
|
||||||
|
mutuallyExclusiveGroupStatus := map[string]map[string]bool{}
|
||||||
|
c.Flags().VisitAll(func(pflag *flag.Flag) {
|
||||||
|
processFlagForGroupAnnotation(flags, pflag, requiredAsGroup, groupStatus)
|
||||||
|
processFlagForGroupAnnotation(flags, pflag, mutuallyExclusive, mutuallyExclusiveGroupStatus)
|
||||||
|
})
|
||||||
|
|
||||||
|
// If a flag that is part of a group is present, we make all the other flags
|
||||||
|
// of that group required so that the shell completion suggests them automatically
|
||||||
|
for flagList, flagnameAndStatus := range groupStatus {
|
||||||
|
for _, isSet := range flagnameAndStatus {
|
||||||
|
if isSet {
|
||||||
|
// One of the flags of the group is set, mark the other ones as required
|
||||||
|
for _, fName := range strings.Split(flagList, " ") {
|
||||||
|
_ = c.MarkFlagRequired(fName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a flag that is mutually exclusive to others is present, we hide the other
|
||||||
|
// flags of that group so the shell completion does not suggest them
|
||||||
|
for flagList, flagnameAndStatus := range mutuallyExclusiveGroupStatus {
|
||||||
|
for flagName, isSet := range flagnameAndStatus {
|
||||||
|
if isSet {
|
||||||
|
// One of the flags of the mutually exclusive group is set, mark the other ones as hidden
|
||||||
|
// Don't mark the flag that is already set as hidden because it may be an
|
||||||
|
// array or slice flag and therefore must continue being suggested
|
||||||
|
for _, fName := range strings.Split(flagList, " ") {
|
||||||
|
if fName != flagName {
|
||||||
|
flag := c.Flags().Lookup(fName)
|
||||||
|
flag.Hidden = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
152
flag_groups_test.go
Normal file
152
flag_groups_test.go
Normal file
|
@ -0,0 +1,152 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestValidateFlagGroups(t *testing.T) {
|
||||||
|
getCmd := func() *Command {
|
||||||
|
c := &Command{
|
||||||
|
Use: "testcmd",
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
}}
|
||||||
|
// Define lots of flags to utilize for testing.
|
||||||
|
for _, v := range []string{"a", "b", "c", "d"} {
|
||||||
|
c.Flags().String(v, "", "")
|
||||||
|
}
|
||||||
|
for _, v := range []string{"e", "f", "g"} {
|
||||||
|
c.PersistentFlags().String(v, "", "")
|
||||||
|
}
|
||||||
|
subC := &Command{
|
||||||
|
Use: "subcmd",
|
||||||
|
Run: func(cmd *Command, args []string) {
|
||||||
|
}}
|
||||||
|
subC.Flags().String("subonly", "", "")
|
||||||
|
c.AddCommand(subC)
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
||||||
|
// Each test case uses a unique command from the function above.
|
||||||
|
testcases := []struct {
|
||||||
|
desc string
|
||||||
|
flagGroupsRequired []string
|
||||||
|
flagGroupsExclusive []string
|
||||||
|
subCmdFlagGroupsRequired []string
|
||||||
|
subCmdFlagGroupsExclusive []string
|
||||||
|
args []string
|
||||||
|
expectErr string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "No flags no problem",
|
||||||
|
}, {
|
||||||
|
desc: "No flags no problem even with conflicting groups",
|
||||||
|
flagGroupsRequired: []string{"a b"},
|
||||||
|
flagGroupsExclusive: []string{"a b"},
|
||||||
|
}, {
|
||||||
|
desc: "Required flag group not satisfied",
|
||||||
|
flagGroupsRequired: []string{"a b c"},
|
||||||
|
args: []string{"--a=foo"},
|
||||||
|
expectErr: "if any flags in the group [a b c] are set they must all be set; missing [b c]",
|
||||||
|
}, {
|
||||||
|
desc: "Exclusive flag group not satisfied",
|
||||||
|
flagGroupsExclusive: []string{"a b c"},
|
||||||
|
args: []string{"--a=foo", "--b=foo"},
|
||||||
|
expectErr: "if any flags in the group [a b c] are set none of the others can be; [a b] were all set",
|
||||||
|
}, {
|
||||||
|
desc: "Multiple required flag group not satisfied returns first error",
|
||||||
|
flagGroupsRequired: []string{"a b c", "a d"},
|
||||||
|
args: []string{"--c=foo", "--d=foo"},
|
||||||
|
expectErr: `if any flags in the group [a b c] are set they must all be set; missing [a b]`,
|
||||||
|
}, {
|
||||||
|
desc: "Multiple exclusive flag group not satisfied returns first error",
|
||||||
|
flagGroupsExclusive: []string{"a b c", "a d"},
|
||||||
|
args: []string{"--a=foo", "--c=foo", "--d=foo"},
|
||||||
|
expectErr: `if any flags in the group [a b c] are set none of the others can be; [a c] were all set`,
|
||||||
|
}, {
|
||||||
|
desc: "Validation of required groups occurs on groups in sorted order",
|
||||||
|
flagGroupsRequired: []string{"a d", "a b", "a c"},
|
||||||
|
args: []string{"--a=foo"},
|
||||||
|
expectErr: `if any flags in the group [a b] are set they must all be set; missing [b]`,
|
||||||
|
}, {
|
||||||
|
desc: "Validation of exclusive groups occurs on groups in sorted order",
|
||||||
|
flagGroupsExclusive: []string{"a d", "a b", "a c"},
|
||||||
|
args: []string{"--a=foo", "--b=foo", "--c=foo"},
|
||||||
|
expectErr: `if any flags in the group [a b] are set none of the others can be; [a b] were all set`,
|
||||||
|
}, {
|
||||||
|
desc: "Persistent flags utilize both features and can fail required groups",
|
||||||
|
flagGroupsRequired: []string{"a e", "e f"},
|
||||||
|
flagGroupsExclusive: []string{"f g"},
|
||||||
|
args: []string{"--a=foo", "--f=foo", "--g=foo"},
|
||||||
|
expectErr: `if any flags in the group [a e] are set they must all be set; missing [e]`,
|
||||||
|
}, {
|
||||||
|
desc: "Persistent flags utilize both features and can fail mutually exclusive groups",
|
||||||
|
flagGroupsRequired: []string{"a e", "e f"},
|
||||||
|
flagGroupsExclusive: []string{"f g"},
|
||||||
|
args: []string{"--a=foo", "--e=foo", "--f=foo", "--g=foo"},
|
||||||
|
expectErr: `if any flags in the group [f g] are set none of the others can be; [f g] were all set`,
|
||||||
|
}, {
|
||||||
|
desc: "Persistent flags utilize both features and can pass",
|
||||||
|
flagGroupsRequired: []string{"a e", "e f"},
|
||||||
|
flagGroupsExclusive: []string{"f g"},
|
||||||
|
args: []string{"--a=foo", "--e=foo", "--f=foo"},
|
||||||
|
}, {
|
||||||
|
desc: "Subcmds can use required groups using inherited flags",
|
||||||
|
subCmdFlagGroupsRequired: []string{"e subonly"},
|
||||||
|
args: []string{"subcmd", "--e=foo", "--subonly=foo"},
|
||||||
|
}, {
|
||||||
|
desc: "Subcmds can use exclusive groups using inherited flags",
|
||||||
|
subCmdFlagGroupsExclusive: []string{"e subonly"},
|
||||||
|
args: []string{"subcmd", "--e=foo", "--subonly=foo"},
|
||||||
|
expectErr: "if any flags in the group [e subonly] are set none of the others can be; [e subonly] were all set",
|
||||||
|
}, {
|
||||||
|
desc: "Subcmds can use exclusive groups using inherited flags and pass",
|
||||||
|
subCmdFlagGroupsExclusive: []string{"e subonly"},
|
||||||
|
args: []string{"subcmd", "--e=foo"},
|
||||||
|
}, {
|
||||||
|
desc: "Flag groups not applied if not found on invoked command",
|
||||||
|
subCmdFlagGroupsRequired: []string{"e subonly"},
|
||||||
|
args: []string{"--e=foo"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range testcases {
|
||||||
|
t.Run(tc.desc, func(t *testing.T) {
|
||||||
|
c := getCmd()
|
||||||
|
sub := c.Commands()[0]
|
||||||
|
for _, flagGroup := range tc.flagGroupsRequired {
|
||||||
|
c.MarkFlagsRequiredTogether(strings.Split(flagGroup, " ")...)
|
||||||
|
}
|
||||||
|
for _, flagGroup := range tc.flagGroupsExclusive {
|
||||||
|
c.MarkFlagsMutuallyExclusive(strings.Split(flagGroup, " ")...)
|
||||||
|
}
|
||||||
|
for _, flagGroup := range tc.subCmdFlagGroupsRequired {
|
||||||
|
sub.MarkFlagsRequiredTogether(strings.Split(flagGroup, " ")...)
|
||||||
|
}
|
||||||
|
for _, flagGroup := range tc.subCmdFlagGroupsExclusive {
|
||||||
|
sub.MarkFlagsMutuallyExclusive(strings.Split(flagGroup, " ")...)
|
||||||
|
}
|
||||||
|
c.SetArgs(tc.args)
|
||||||
|
err := c.Execute()
|
||||||
|
switch {
|
||||||
|
case err == nil && len(tc.expectErr) > 0:
|
||||||
|
t.Errorf("Expected error %q but got nil", tc.expectErr)
|
||||||
|
case err != nil && err.Error() != tc.expectErr:
|
||||||
|
t.Errorf("Expected error %q but got %q", tc.expectErr, err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
9
go.mod
9
go.mod
|
@ -1,11 +1,10 @@
|
||||||
module github.com/spf13/cobra
|
module github.com/spf13/cobra
|
||||||
|
|
||||||
go 1.14
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.1
|
github.com/cpuguy83/go-md2man/v2 v2.0.2
|
||||||
github.com/inconshreveable/mousetrap v1.0.0
|
github.com/inconshreveable/mousetrap v1.0.1
|
||||||
github.com/spf13/pflag v1.0.5
|
github.com/spf13/pflag v1.0.5
|
||||||
github.com/spf13/viper v1.8.1
|
gopkg.in/yaml.v3 v3.0.1
|
||||||
gopkg.in/yaml.v2 v2.4.0
|
|
||||||
)
|
)
|
||||||
|
|
592
go.sum
592
go.sum
|
@ -1,590 +1,12 @@
|
||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
|
||||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||||
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
|
||||||
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
|
||||||
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
|
||||||
cloud.google.com/go v0.50.0/go.mod h1:r9sluTvynVuxRIOHXQEHMFffphuXHOMZMycpNR5e6To=
|
|
||||||
cloud.google.com/go v0.52.0/go.mod h1:pXajvRH/6o3+F9jDHZWQ5PbGhn+o8w9qiu/CffaVdO4=
|
|
||||||
cloud.google.com/go v0.53.0/go.mod h1:fp/UouUEsRkN6ryDKNW/Upv/JBKnv6WDthjR6+vze6M=
|
|
||||||
cloud.google.com/go v0.54.0/go.mod h1:1rq2OEkV3YMf6n/9ZvGWI3GWw0VoqH/1x2nd8Is/bPc=
|
|
||||||
cloud.google.com/go v0.56.0/go.mod h1:jr7tqZxxKOVYizybht9+26Z/gUq7tiRzu+ACVAMbKVk=
|
|
||||||
cloud.google.com/go v0.57.0/go.mod h1:oXiQ6Rzq3RAkkY7N6t3TcE6jE+CIBBbA36lwQ1JyzZs=
|
|
||||||
cloud.google.com/go v0.62.0/go.mod h1:jmCYTdRCQuc1PHIIJ/maLInMho30T/Y0M4hTdTShOYc=
|
|
||||||
cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHObY=
|
|
||||||
cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI=
|
|
||||||
cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk=
|
|
||||||
cloud.google.com/go v0.78.0/go.mod h1:QjdrLG0uq+YwhjoVOLsS1t7TW8fs36kLs4XO5R5ECHg=
|
|
||||||
cloud.google.com/go v0.79.0/go.mod h1:3bzgcEeQlzbuEAYu4mrWhKqWjmpprinYgKJLgKHnbb8=
|
|
||||||
cloud.google.com/go v0.81.0/go.mod h1:mk/AM35KwGk/Nm2YSeZbxXdrNK3KZOYHmLkOqC2V6E0=
|
|
||||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
|
||||||
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
|
|
||||||
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
|
|
||||||
cloud.google.com/go/bigquery v1.5.0/go.mod h1:snEHRnqQbz117VIFhE8bmtwIDY80NLUZUMb4Nv6dBIg=
|
|
||||||
cloud.google.com/go/bigquery v1.7.0/go.mod h1://okPTzCYNXSlb24MZs83e2Do+h+VXtc4gLoIoXIAPc=
|
|
||||||
cloud.google.com/go/bigquery v1.8.0/go.mod h1:J5hqkt3O0uAFnINi6JXValWIb1v0goeZM77hZzJN/fQ=
|
|
||||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
|
||||||
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
|
|
||||||
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
|
|
||||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
|
||||||
cloud.google.com/go/pubsub v1.1.0/go.mod h1:EwwdRX2sKPjnvnqCa270oGRyludottCI76h+R3AArQw=
|
|
||||||
cloud.google.com/go/pubsub v1.2.0/go.mod h1:jhfEVHT8odbXTkndysNHCcx0awwzvfOlguIAii9o8iA=
|
|
||||||
cloud.google.com/go/pubsub v1.3.1/go.mod h1:i+ucay31+CNRpDW4Lu78I4xXG+O1r/MAHgjpRVR+TSU=
|
|
||||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
|
||||||
cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0ZeosJ0Rtdos=
|
|
||||||
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
|
|
||||||
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
|
|
||||||
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
|
|
||||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
|
||||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
|
||||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
|
||||||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
|
||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
|
||||||
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
|
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
|
||||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
|
||||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
|
||||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
|
||||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
|
||||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
|
||||||
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
|
||||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
|
||||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
|
||||||
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKYj/3DxU=
|
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
|
||||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
|
||||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
|
||||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
|
||||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
|
||||||
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
|
|
||||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
|
||||||
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
|
|
||||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
|
||||||
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
|
||||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
|
||||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
|
||||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
|
||||||
github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
|
||||||
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
|
||||||
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
|
|
||||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
|
||||||
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
|
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
|
||||||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
|
||||||
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
|
||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
|
||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
|
||||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
|
||||||
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
|
|
||||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
|
||||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
|
||||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
|
||||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
|
||||||
github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
|
||||||
github.com/google/martian/v3 v3.1.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0=
|
|
||||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
|
||||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
|
||||||
github.com/google/pprof v0.0.0-20191218002539-d4f498aebedc/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
|
||||||
github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
|
||||||
github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
|
||||||
github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
|
||||||
github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM=
|
|
||||||
github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
|
||||||
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
|
||||||
github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
|
||||||
github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
|
||||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
|
||||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
|
||||||
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
|
|
||||||
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
|
|
||||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
|
||||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
|
||||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
|
||||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
|
||||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
|
||||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
|
||||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
||||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
|
||||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
|
||||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
|
||||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
|
||||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
|
||||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
|
||||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
|
||||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
|
||||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
|
||||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
|
||||||
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
|
|
||||||
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
|
|
||||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
|
||||||
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
|
|
||||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
|
||||||
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
|
|
||||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
|
||||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
|
|
||||||
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
|
||||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
|
||||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
|
||||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
|
||||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
|
||||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
|
||||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
|
||||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
|
||||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1 h1:CpVNEelQCZBooIPDn+AR3NpivK/TIKU8bDxdASFVQag=
|
|
||||||
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
|
||||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
|
||||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
|
||||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
|
||||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
|
||||||
github.com/pelletier/go-toml v1.9.3 h1:zeC5b1GviRUyKYd6OJPvBU/mcVDVoL1OhT17FCt5dSQ=
|
|
||||||
github.com/pelletier/go-toml v1.9.3/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c=
|
|
||||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
|
||||||
github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZI=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
|
||||||
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
|
|
||||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
|
||||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
|
||||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
|
|
||||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
|
||||||
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
|
|
||||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
|
||||||
github.com/spf13/afero v1.6.0 h1:xoax2sJ2DT8S8xA2paPFjDCScCNeWsg75VG0DLRreiY=
|
|
||||||
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
|
|
||||||
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
|
|
||||||
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
|
||||||
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
|
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
github.com/spf13/viper v1.8.1 h1:Kq1fyeebqsBfbjZj4EL7gj2IO0mMaiyjYUWcUsl2O44=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
||||||
github.com/spf13/viper v1.8.1/go.mod h1:o0Pch8wJ9BVSWGQMbra6iw0oQ5oktSIBaujf1rJH9Ns=
|
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
|
||||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
|
||||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
|
||||||
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
|
|
||||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
|
||||||
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
|
||||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
|
||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
|
||||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
|
||||||
go.etcd.io/etcd/api/v3 v3.5.0/go.mod h1:cbVKeC6lCfl7j/8jBhAK6aIYO9XOjdptoxU/nLQcPvs=
|
|
||||||
go.etcd.io/etcd/client/pkg/v3 v3.5.0/go.mod h1:IJHfcCEKxYu1Os13ZdwCwIUTUVGYTSAM3YSwc9/Ac1g=
|
|
||||||
go.etcd.io/etcd/client/v2 v2.305.0/go.mod h1:h9puh54ZTgAKtEbut2oe9P4L/oqKCVB6xsXlzd7alYQ=
|
|
||||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
|
||||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
|
||||||
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
|
||||||
go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
|
||||||
go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
|
|
||||||
go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk=
|
|
||||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
|
||||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
|
||||||
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
|
|
||||||
go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
|
|
||||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
|
||||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
|
||||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
|
||||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
|
||||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
|
||||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
|
||||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
|
||||||
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
|
||||||
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
|
||||||
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
|
|
||||||
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
|
|
||||||
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
|
|
||||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
|
||||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
|
||||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
|
||||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
|
||||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
|
||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
|
||||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
|
||||||
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
|
||||||
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
|
||||||
golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
|
||||||
golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
|
||||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
|
||||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
|
||||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
|
||||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
|
||||||
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
|
||||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
|
||||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
|
||||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
|
||||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
||||||
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
||||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
|
||||||
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20210316092652-d523dce5a7f4/go.mod h1:RBQZq4jEuRlivfhVLdyRGr576XBO4/greRjx4P4O3yc=
|
|
||||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210313182246-cd4f82c27b84/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20210402161424-2e8d93401602/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
|
|
||||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200113162924-86b910548bc1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200331124033-c3d80250170d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200501052902-10377860bb8e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200511232937-7e40ca221e25/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210315160823-c6e025ad8005/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210403161142-5e06dd20ab57/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
|
|
||||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
|
|
||||||
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
|
||||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
|
||||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
|
||||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
|
||||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191113191852-77e3bb0ad9e7/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191115202509-3a792d9c32b2/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200204074204-1cc6d1ef6c74/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200207183749-b753a1ba74fa/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200212150539-ea181f53ac56/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200224181240-023911ca70b2/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200227222343-706bc42d1f0d/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
|
||||||
golang.org/x/tools v0.0.0-20200304193943-95d2e580d8eb/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
|
||||||
golang.org/x/tools v0.0.0-20200312045724-11d5b4c81c7d/go.mod h1:o4KQGtdN14AW+yjsvvwRTJJuXz8XRtIHtEnmAXLyFUw=
|
|
||||||
golang.org/x/tools v0.0.0-20200331025713-a30bf2db82d4/go.mod h1:Sl4aGygMT6LrqrWclx+PTx3U+LnKx/seiNR+3G19Ar8=
|
|
||||||
golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
|
||||||
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
|
||||||
golang.org/x/tools v0.0.0-20200515010526-7d3b6ebf133d/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
|
||||||
golang.org/x/tools v0.0.0-20200618134242-20370b0cb4b2/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
|
||||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
|
||||||
golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
|
||||||
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
|
||||||
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
|
|
||||||
golang.org/x/tools v0.0.0-20200904185747-39188db58858/go.mod h1:Cj7w3i3Rnn0Xh82ur9kSqwfTHTeVxaDqrfMjpcNT6bE=
|
|
||||||
golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
|
||||||
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
|
|
||||||
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
|
||||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
|
||||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
|
||||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
|
||||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
|
||||||
google.golang.org/api v0.14.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
|
||||||
google.golang.org/api v0.15.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
|
||||||
google.golang.org/api v0.17.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
|
||||||
google.golang.org/api v0.18.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
|
||||||
google.golang.org/api v0.19.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
|
||||||
google.golang.org/api v0.20.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
|
||||||
google.golang.org/api v0.22.0/go.mod h1:BwFmGc8tA3vsd7r/7kR8DY7iEEGSU04BFxCo5jP/sfE=
|
|
||||||
google.golang.org/api v0.24.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
|
||||||
google.golang.org/api v0.28.0/go.mod h1:lIXQywCXRcnZPGlsd8NbLnOjtAoL6em04bJ9+z0MncE=
|
|
||||||
google.golang.org/api v0.29.0/go.mod h1:Lcubydp8VUV7KeIHD9z2Bys/sm/vGKnG1UHuDBSrHWM=
|
|
||||||
google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz5138Fc=
|
|
||||||
google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
|
|
||||||
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
|
|
||||||
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
|
|
||||||
google.golang.org/api v0.41.0/go.mod h1:RkxM5lITDfTzmyKFPt+wGrCJbVfniCr2ool8kTBzRTU=
|
|
||||||
google.golang.org/api v0.43.0/go.mod h1:nQsDGjRXMo4lvh5hP0TKqF244gqhGcr/YSIykhUk/94=
|
|
||||||
google.golang.org/api v0.44.0/go.mod h1:EBOGZqzyhtvMDoxwS97ctnh0zUmYY6CxqXsc1AvkYD8=
|
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
|
||||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
|
||||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
|
||||||
google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
|
||||||
google.golang.org/appengine v1.6.7/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
|
||||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
|
||||||
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
|
||||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
|
||||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20191115194625-c23dd37a84c9/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20191230161307-f3c370f40bfb/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20200115191322-ca5a22157cba/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20200122232147-0452cf42e150/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
|
||||||
google.golang.org/genproto v0.0.0-20200204135345-fa8e72b47b90/go.mod h1:GmwEX6Z4W5gMy59cAlVYjN9JhxgbQH6Gn+gFDQe2lzA=
|
|
||||||
google.golang.org/genproto v0.0.0-20200212174721-66ed5ce911ce/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200224152610-e50cd9704f63/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200228133532-8c2c7df3a383/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200305110556-506484158171/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200312145019-da6875a35672/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200331122359-1ee6d9798940/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200430143042-b979b6f78d84/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200511104702-f5ebc3bea380/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200513103714-09dca8ec2884/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
|
|
||||||
google.golang.org/genproto v0.0.0-20200515170657-fc4c6c6a6587/go.mod h1:YsZOwe1myG/8QRHRsmBRE1LrgQY60beZKjly0O1fX9U=
|
|
||||||
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo=
|
|
||||||
google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
|
|
||||||
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20200904004341-0bd0a958aa1d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20201109203340-2640f1f9cdfb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20210222152913-aa3ee6e6a81c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20210303154014-9728d6b83eeb/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20210310155132-4ce2db91004e/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20210319143718-93e7006c17a6/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
|
|
||||||
google.golang.org/genproto v0.0.0-20210402141018-6c239bbf2bb1/go.mod h1:9lPAdzaEmUacj36I+k7YKbEc5CXzPIeORRgDAUOu28A=
|
|
||||||
google.golang.org/genproto v0.0.0-20210602131652-f16073e35f0c/go.mod h1:UODoCrxHCcBojKKwX1terBiRUaqAsFqJiF615XL43r0=
|
|
||||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
|
||||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
|
||||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
|
||||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
|
||||||
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
|
|
||||||
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
|
||||||
google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
|
||||||
google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
|
|
||||||
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
|
|
||||||
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
|
|
||||||
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
|
||||||
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
|
||||||
google.golang.org/grpc v1.31.1/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
|
|
||||||
google.golang.org/grpc v1.33.1/go.mod h1:fr5YgcSWrqhRRxogOsw7RzIpsmvOZ6IcH4kBYTpR3n0=
|
|
||||||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
|
||||||
google.golang.org/grpc v1.34.0/go.mod h1:WotjhfgOW/POjDeRt8vscBtXq+2VjORFy659qA51WJ8=
|
|
||||||
google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
|
||||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
|
||||||
google.golang.org/grpc v1.36.1/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
|
||||||
google.golang.org/grpc v1.38.0/go.mod h1:NREThFqKR1f3iQ6oBuvc5LadQuXVGo9rkm5ZGrQdJfM=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
|
||||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
|
||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
|
||||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
|
||||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
|
||||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
|
||||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
|
||||||
gopkg.in/ini.v1 v1.62.0 h1:duBzk771uxoUuOlyRLkHsygud9+5lrlGjdFBb4mSKDU=
|
|
||||||
gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
|
|
||||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
||||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
||||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
||||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
||||||
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
||||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
|
||||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
|
||||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
|
||||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
|
||||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
|
||||||
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
// The generated scripts require PowerShell v5.0+ (which comes Windows 10, but
|
// The generated scripts require PowerShell v5.0+ (which comes Windows 10, but
|
||||||
// can be downloaded separately for windows 7 or 8.1).
|
// can be downloaded separately for windows 7 or 8.1).
|
||||||
|
|
||||||
|
@ -8,9 +22,15 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {
|
func genPowerShellComp(buf io.StringWriter, name string, includeDesc bool) {
|
||||||
|
// Variables should not contain a '-' or ':' character
|
||||||
|
nameForVar := name
|
||||||
|
nameForVar = strings.Replace(nameForVar, "-", "_", -1)
|
||||||
|
nameForVar = strings.Replace(nameForVar, ":", "_", -1)
|
||||||
|
|
||||||
compCmd := ShellCompRequestCmd
|
compCmd := ShellCompRequestCmd
|
||||||
if !includeDesc {
|
if !includeDesc {
|
||||||
compCmd = ShellCompNoDescRequestCmd
|
compCmd = ShellCompNoDescRequestCmd
|
||||||
|
@ -27,7 +47,7 @@ filter __%[1]s_escapeStringWithSpecialChars {
|
||||||
`+" $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|\"|`|\\||<|>|&','`$&'"+`
|
`+" $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|\"|`|\\||<|>|&','`$&'"+`
|
||||||
}
|
}
|
||||||
|
|
||||||
Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock {
|
[scriptblock]$__%[2]sCompleterBlock = {
|
||||||
param(
|
param(
|
||||||
$WordToComplete,
|
$WordToComplete,
|
||||||
$CommandAst,
|
$CommandAst,
|
||||||
|
@ -52,16 +72,17 @@ Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock {
|
||||||
}
|
}
|
||||||
__%[1]s_debug "Truncated command: $Command"
|
__%[1]s_debug "Truncated command: $Command"
|
||||||
|
|
||||||
$ShellCompDirectiveError=%[3]d
|
$ShellCompDirectiveError=%[4]d
|
||||||
$ShellCompDirectiveNoSpace=%[4]d
|
$ShellCompDirectiveNoSpace=%[5]d
|
||||||
$ShellCompDirectiveNoFileComp=%[5]d
|
$ShellCompDirectiveNoFileComp=%[6]d
|
||||||
$ShellCompDirectiveFilterFileExt=%[6]d
|
$ShellCompDirectiveFilterFileExt=%[7]d
|
||||||
$ShellCompDirectiveFilterDirs=%[7]d
|
$ShellCompDirectiveFilterDirs=%[8]d
|
||||||
|
|
||||||
# Prepare the command to request completions for the program.
|
# Prepare the command to request completions for the program.
|
||||||
# Split the command at the first space to separate the program and arguments.
|
# Split the command at the first space to separate the program and arguments.
|
||||||
$Program,$Arguments = $Command.Split(" ",2)
|
$Program,$Arguments = $Command.Split(" ",2)
|
||||||
$RequestComp="$Program %[2]s $Arguments"
|
|
||||||
|
$RequestComp="$Program %[3]s $Arguments"
|
||||||
__%[1]s_debug "RequestComp: $RequestComp"
|
__%[1]s_debug "RequestComp: $RequestComp"
|
||||||
|
|
||||||
# we cannot use $WordToComplete because it
|
# we cannot use $WordToComplete because it
|
||||||
|
@ -90,11 +111,13 @@ Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
__%[1]s_debug "Calling $RequestComp"
|
__%[1]s_debug "Calling $RequestComp"
|
||||||
|
# First disable ActiveHelp which is not supported for Powershell
|
||||||
|
$env:%[9]s=0
|
||||||
|
|
||||||
#call the command store the output in $out and redirect stderr and stdout to null
|
#call the command store the output in $out and redirect stderr and stdout to null
|
||||||
# $Out is an array contains each line per element
|
# $Out is an array contains each line per element
|
||||||
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
|
Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
|
||||||
|
|
||||||
|
|
||||||
# get directive from last line
|
# get directive from last line
|
||||||
[int]$Directive = $Out[-1].TrimStart(':')
|
[int]$Directive = $Out[-1].TrimStart(':')
|
||||||
if ($Directive -eq "") {
|
if ($Directive -eq "") {
|
||||||
|
@ -233,16 +256,18 @@ Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock {
|
||||||
Default {
|
Default {
|
||||||
# Like MenuComplete but we don't want to add a space here because
|
# Like MenuComplete but we don't want to add a space here because
|
||||||
# the user need to press space anyway to get the completion.
|
# the user need to press space anyway to get the completion.
|
||||||
# Description will not be shown because thats not possible with TabCompleteNext
|
# Description will not be shown because that's not possible with TabCompleteNext
|
||||||
[System.Management.Automation.CompletionResult]::new($($comp.Name | __%[1]s_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
[System.Management.Automation.CompletionResult]::new($($comp.Name | __%[1]s_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`, name, compCmd,
|
|
||||||
|
Register-ArgumentCompleter -CommandName '%[1]s' -ScriptBlock $__%[2]sCompleterBlock
|
||||||
|
`, name, nameForVar, compCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs, activeHelpEnvVar(name)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Command) genPowerShellCompletion(w io.Writer, includeDesc bool) error {
|
func (c *Command) genPowerShellCompletion(w io.Writer, includeDesc bool) error {
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
// Copyright © 2015 Steve Francia <spf@spf13.com>.
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
//
|
//
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
// you may not use this file except in compliance with the License.
|
// you may not use this file except in compliance with the License.
|
||||||
// You may obtain a copy of the License at
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
//
|
//
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
@ -11,16 +12,22 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package main
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"bytes"
|
||||||
|
"fmt"
|
||||||
"github.com/spf13/cobra/cobra/cmd"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func TestPwshCompletionNoActiveHelp(t *testing.T) {
|
||||||
if err := cmd.Execute(); err != nil {
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
os.Exit(1)
|
|
||||||
}
|
buf := new(bytes.Buffer)
|
||||||
|
assertNoErr(t, c.GenPowerShellCompletion(buf))
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
// check that active help is being disabled
|
||||||
|
activeHelpVar := activeHelpEnvVar(c.Name())
|
||||||
|
check(t, output, fmt.Sprintf("%s=0", activeHelpVar))
|
||||||
}
|
}
|
|
@ -1,39 +1,60 @@
|
||||||
## Projects using Cobra
|
## Projects using Cobra
|
||||||
|
|
||||||
|
- [Allero](https://github.com/allero-io/allero)
|
||||||
- [Arduino CLI](https://github.com/arduino/arduino-cli)
|
- [Arduino CLI](https://github.com/arduino/arduino-cli)
|
||||||
- [Bleve](http://www.blevesearch.com/)
|
- [Bleve](https://blevesearch.com/)
|
||||||
- [CockroachDB](http://www.cockroachlabs.com/)
|
- [Cilium](https://cilium.io/)
|
||||||
|
- [CloudQuery](https://github.com/cloudquery/cloudquery)
|
||||||
|
- [CockroachDB](https://www.cockroachlabs.com/)
|
||||||
- [Cosmos SDK](https://github.com/cosmos/cosmos-sdk)
|
- [Cosmos SDK](https://github.com/cosmos/cosmos-sdk)
|
||||||
|
- [Datree](https://github.com/datreeio/datree)
|
||||||
- [Delve](https://github.com/derekparker/delve)
|
- [Delve](https://github.com/derekparker/delve)
|
||||||
- [Docker (distribution)](https://github.com/docker/distribution)
|
- [Docker (distribution)](https://github.com/docker/distribution)
|
||||||
- [Etcd](https://etcd.io/)
|
- [Etcd](https://etcd.io/)
|
||||||
- [Gardener](https://github.com/gardener/gardenctl)
|
- [Gardener](https://github.com/gardener/gardenctl)
|
||||||
- [Giant Swarm's gsctl](https://github.com/giantswarm/gsctl)
|
- [Giant Swarm's gsctl](https://github.com/giantswarm/gsctl)
|
||||||
- [Git Bump](https://github.com/erdaltsksn/git-bump)
|
- [Git Bump](https://github.com/erdaltsksn/git-bump)
|
||||||
- [Github CLI](https://github.com/cli/cli)
|
- [GitHub CLI](https://github.com/cli/cli)
|
||||||
- [GitHub Labeler](https://github.com/erdaltsksn/gh-label)
|
- [GitHub Labeler](https://github.com/erdaltsksn/gh-label)
|
||||||
- [Golangci-lint](https://golangci-lint.run)
|
- [Golangci-lint](https://golangci-lint.run)
|
||||||
- [GopherJS](http://www.gopherjs.org/)
|
- [GopherJS](https://github.com/gopherjs/gopherjs)
|
||||||
|
- [GoReleaser](https://goreleaser.com)
|
||||||
- [Helm](https://helm.sh)
|
- [Helm](https://helm.sh)
|
||||||
- [Hugo](https://gohugo.io)
|
- [Hugo](https://gohugo.io)
|
||||||
|
- [Infracost](https://github.com/infracost/infracost)
|
||||||
- [Istio](https://istio.io)
|
- [Istio](https://istio.io)
|
||||||
- [Kool](https://github.com/kool-dev/kool)
|
- [Kool](https://github.com/kool-dev/kool)
|
||||||
- [Kubernetes](http://kubernetes.io/)
|
- [Kubernetes](https://kubernetes.io/)
|
||||||
|
- [Kubescape](https://github.com/armosec/kubescape)
|
||||||
|
- [KubeVirt](https://github.com/kubevirt/kubevirt)
|
||||||
- [Linkerd](https://linkerd.io/)
|
- [Linkerd](https://linkerd.io/)
|
||||||
- [Mattermost-server](https://github.com/mattermost/mattermost-server)
|
- [Mattermost-server](https://github.com/mattermost/mattermost-server)
|
||||||
|
- [Mercure](https://mercure.rocks/)
|
||||||
- [Meroxa CLI](https://github.com/meroxa/cli)
|
- [Meroxa CLI](https://github.com/meroxa/cli)
|
||||||
- [Metal Stack CLI](https://github.com/metal-stack/metalctl)
|
- [Metal Stack CLI](https://github.com/metal-stack/metalctl)
|
||||||
- [Moby (former Docker)](https://github.com/moby/moby)
|
- [Moby (former Docker)](https://github.com/moby/moby)
|
||||||
|
- [Moldy](https://github.com/Moldy-Community/moldy)
|
||||||
|
- [Multi-gitter](https://github.com/lindell/multi-gitter)
|
||||||
- [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack)
|
- [Nanobox](https://github.com/nanobox-io/nanobox)/[Nanopack](https://github.com/nanopack)
|
||||||
|
- [nFPM](https://nfpm.goreleaser.com)
|
||||||
|
- [Okteto](https://github.com/okteto/okteto)
|
||||||
- [OpenShift](https://www.openshift.com/)
|
- [OpenShift](https://www.openshift.com/)
|
||||||
- [Ory Hydra](https://github.com/ory/hydra)
|
- [Ory Hydra](https://github.com/ory/hydra)
|
||||||
- [Ory Kratos](https://github.com/ory/kratos)
|
- [Ory Kratos](https://github.com/ory/kratos)
|
||||||
|
- [Pixie](https://github.com/pixie-io/pixie)
|
||||||
|
- [Polygon Edge](https://github.com/0xPolygon/polygon-edge)
|
||||||
- [Pouch](https://github.com/alibaba/pouch)
|
- [Pouch](https://github.com/alibaba/pouch)
|
||||||
- [ProjectAtomic (enterprise)](http://www.projectatomic.io/)
|
- [ProjectAtomic (enterprise)](https://www.projectatomic.io/)
|
||||||
- [Prototool](https://github.com/uber/prototool)
|
- [Prototool](https://github.com/uber/prototool)
|
||||||
|
- [Pulumi](https://www.pulumi.com)
|
||||||
|
- [QRcp](https://github.com/claudiodangelis/qrcp)
|
||||||
- [Random](https://github.com/erdaltsksn/random)
|
- [Random](https://github.com/erdaltsksn/random)
|
||||||
- [Rclone](https://rclone.org/)
|
- [Rclone](https://rclone.org/)
|
||||||
|
- [Scaleway CLI](https://github.com/scaleway/scaleway-cli)
|
||||||
- [Skaffold](https://skaffold.dev/)
|
- [Skaffold](https://skaffold.dev/)
|
||||||
- [Tendermint](https://github.com/tendermint/tendermint)
|
- [Tendermint](https://github.com/tendermint/tendermint)
|
||||||
- [Twitch CLI](https://github.com/twitchdev/twitch-cli)
|
- [Twitch CLI](https://github.com/twitchdev/twitch-cli)
|
||||||
|
- [UpCloud CLI (`upctl`)](https://github.com/UpCloudLtd/upcloud-cli)
|
||||||
|
- VMware's [Tanzu Community Edition](https://github.com/vmware-tanzu/community-edition) & [Tanzu Framework](https://github.com/vmware-tanzu/tanzu-framework)
|
||||||
- [Werf](https://werf.io/)
|
- [Werf](https://werf.io/)
|
||||||
|
- [ZITADEL](https://github.com/zitadel/zitadel)
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -16,10 +16,12 @@ If you do not wish to use the default `completion` command, you can choose to
|
||||||
provide your own, which will take precedence over the default one. (This also provides
|
provide your own, which will take precedence over the default one. (This also provides
|
||||||
backwards-compatibility with programs that already have their own `completion` command.)
|
backwards-compatibility with programs that already have their own `completion` command.)
|
||||||
|
|
||||||
If you are using the generator, you can create a completion command by running
|
If you are using the `cobra-cli` generator,
|
||||||
|
which can be found at [spf13/cobra-cli](https://github.com/spf13/cobra-cli),
|
||||||
|
you can create a completion command by running
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cobra add completion
|
cobra-cli add completion
|
||||||
```
|
```
|
||||||
and then modifying the generated `cmd/completion.go` file to look something like this
|
and then modifying the generated `cmd/completion.go` file to look something like this
|
||||||
(writing the shell script to stdout allows the most flexible use):
|
(writing the shell script to stdout allows the most flexible use):
|
||||||
|
@ -28,17 +30,17 @@ and then modifying the generated `cmd/completion.go` file to look something like
|
||||||
var completionCmd = &cobra.Command{
|
var completionCmd = &cobra.Command{
|
||||||
Use: "completion [bash|zsh|fish|powershell]",
|
Use: "completion [bash|zsh|fish|powershell]",
|
||||||
Short: "Generate completion script",
|
Short: "Generate completion script",
|
||||||
Long: `To load completions:
|
Long: fmt.Sprintf(`To load completions:
|
||||||
|
|
||||||
Bash:
|
Bash:
|
||||||
|
|
||||||
$ source <(yourprogram completion bash)
|
$ source <(%[1]s completion bash)
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# To load completions for each session, execute once:
|
||||||
# Linux:
|
# Linux:
|
||||||
$ yourprogram completion bash > /etc/bash_completion.d/yourprogram
|
$ %[1]s completion bash > /etc/bash_completion.d/%[1]s
|
||||||
# macOS:
|
# macOS:
|
||||||
$ yourprogram completion bash > /usr/local/etc/bash_completion.d/yourprogram
|
$ %[1]s completion bash > $(brew --prefix)/etc/bash_completion.d/%[1]s
|
||||||
|
|
||||||
Zsh:
|
Zsh:
|
||||||
|
|
||||||
|
@ -48,25 +50,25 @@ Zsh:
|
||||||
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
$ echo "autoload -U compinit; compinit" >> ~/.zshrc
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# To load completions for each session, execute once:
|
||||||
$ yourprogram completion zsh > "${fpath[1]}/_yourprogram"
|
$ %[1]s completion zsh > "${fpath[1]}/_%[1]s"
|
||||||
|
|
||||||
# You will need to start a new shell for this setup to take effect.
|
# You will need to start a new shell for this setup to take effect.
|
||||||
|
|
||||||
fish:
|
fish:
|
||||||
|
|
||||||
$ yourprogram completion fish | source
|
$ %[1]s completion fish | source
|
||||||
|
|
||||||
# To load completions for each session, execute once:
|
# To load completions for each session, execute once:
|
||||||
$ yourprogram completion fish > ~/.config/fish/completions/yourprogram.fish
|
$ %[1]s completion fish > ~/.config/fish/completions/%[1]s.fish
|
||||||
|
|
||||||
PowerShell:
|
PowerShell:
|
||||||
|
|
||||||
PS> yourprogram completion powershell | Out-String | Invoke-Expression
|
PS> %[1]s completion powershell | Out-String | Invoke-Expression
|
||||||
|
|
||||||
# To load completions for every new session, run:
|
# To load completions for every new session, run:
|
||||||
PS> yourprogram completion powershell > yourprogram.ps1
|
PS> %[1]s completion powershell > %[1]s.ps1
|
||||||
# and source this file from your PowerShell profile.
|
# and source this file from your PowerShell profile.
|
||||||
`,
|
`,cmd.Root().Name()),
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
|
||||||
Args: cobra.ExactValidArgs(1),
|
Args: cobra.ExactValidArgs(1),
|
||||||
|
@ -97,6 +99,11 @@ To tell Cobra *not* to provide the default `completion` command:
|
||||||
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
rootCmd.CompletionOptions.DisableDefaultCmd = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To tell Cobra to mark the default `completion` command as *hidden*:
|
||||||
|
```
|
||||||
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||||
|
```
|
||||||
|
|
||||||
To tell Cobra *not* to provide the user with the `--no-descriptions` flag to the completion sub-commands:
|
To tell Cobra *not* to provide the user with the `--no-descriptions` flag to the completion sub-commands:
|
||||||
```
|
```
|
||||||
rootCmd.CompletionOptions.DisableNoDescFlag = true
|
rootCmd.CompletionOptions.DisableNoDescFlag = true
|
||||||
|
@ -120,7 +127,7 @@ For example, if you want `kubectl get [tab][tab]` to show a list of valid "nouns
|
||||||
Some simplified code from `kubectl get` looks like:
|
Some simplified code from `kubectl get` looks like:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
validArgs []string = { "pod", "node", "service", "replicationcontroller" }
|
validArgs = []string{ "pod", "node", "service", "replicationcontroller" }
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
|
Use: "get [(-o|--output=)json|yaml|template|...] (RESOURCE [NAME] | RESOURCE/NAME ...)",
|
||||||
|
@ -146,7 +153,7 @@ node pod replicationcontroller service
|
||||||
If your nouns have aliases, you can define them alongside `ValidArgs` using `ArgAliases`:
|
If your nouns have aliases, you can define them alongside `ValidArgs` using `ArgAliases`:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
argAliases []string = { "pods", "nodes", "services", "svc", "replicationcontrollers", "rc" }
|
argAliases = []string { "pods", "nodes", "services", "svc", "replicationcontrollers", "rc" }
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
...
|
...
|
||||||
|
@ -528,6 +535,21 @@ search for a keyword in charts
|
||||||
$ helm s[tab]
|
$ helm s[tab]
|
||||||
search show status
|
search show status
|
||||||
```
|
```
|
||||||
|
### Aliases
|
||||||
|
|
||||||
|
You can also configure `powershell` aliases for your program and they will also support completions.
|
||||||
|
|
||||||
|
```
|
||||||
|
$ sal aliasname origcommand
|
||||||
|
$ Register-ArgumentCompleter -CommandName 'aliasname' -ScriptBlock $__origcommandCompleterBlock
|
||||||
|
|
||||||
|
# and now when you run `aliasname` completion will make
|
||||||
|
# suggestions as it did for `origcommand`.
|
||||||
|
|
||||||
|
$ aliasname <tab>
|
||||||
|
completion firstcommand secondcommand
|
||||||
|
```
|
||||||
|
The name of the completer block variable is of the form `$__<programName>CompleterBlock` where every `-` and `:` in the program name have been replaced with `_`, to respect powershell naming syntax.
|
||||||
|
|
||||||
### Limitations
|
### Limitations
|
||||||
|
|
||||||
|
|
114
user_guide.md
114
user_guide.md
|
@ -29,10 +29,10 @@ func main() {
|
||||||
|
|
||||||
## Using the Cobra Generator
|
## Using the Cobra Generator
|
||||||
|
|
||||||
Cobra provides its own program that will create your application and add any
|
Cobra-CLI is its own program that will create your application and add any
|
||||||
commands you want. It's the easiest way to incorporate Cobra into your application.
|
commands you want. It's the easiest way to incorporate Cobra into your application.
|
||||||
|
|
||||||
[Here](https://github.com/spf13/cobra/blob/master/cobra/README.md) you can find more information about it.
|
For complete details on using the Cobra generator, please refer to [The Cobra-CLI Generator README](https://github.com/spf13/cobra-cli/blob/main/README.md)
|
||||||
|
|
||||||
## Using the Cobra Library
|
## Using the Cobra Library
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ var rootCmd = &cobra.Command{
|
||||||
Short: "Hugo is a very fast static site generator",
|
Short: "Hugo is a very fast static site generator",
|
||||||
Long: `A Fast and Flexible Static Site Generator built with
|
Long: `A Fast and Flexible Static Site Generator built with
|
||||||
love by spf13 and friends in Go.
|
love by spf13 and friends in Go.
|
||||||
Complete documentation is available at http://hugo.spf13.com`,
|
Complete documentation is available at https://gohugo.io/documentation/`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// Do Stuff Here
|
// Do Stuff Here
|
||||||
},
|
},
|
||||||
|
@ -86,7 +86,7 @@ var (
|
||||||
userLicense string
|
userLicense string
|
||||||
|
|
||||||
rootCmd = &cobra.Command{
|
rootCmd = &cobra.Command{
|
||||||
Use: "cobra",
|
Use: "cobra-cli",
|
||||||
Short: "A generator for Cobra based Applications",
|
Short: "A generator for Cobra based Applications",
|
||||||
Long: `Cobra is a CLI library for Go that empowers applications.
|
Long: `Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
|
@ -281,7 +281,7 @@ func init() {
|
||||||
|
|
||||||
In this example, the persistent flag `author` is bound with `viper`.
|
In this example, the persistent flag `author` is bound with `viper`.
|
||||||
**Note**: the variable `author` will not be set to the value from config,
|
**Note**: the variable `author` will not be set to the value from config,
|
||||||
when the `--author` flag is not provided by user.
|
when the `--author` flag is provided by user.
|
||||||
|
|
||||||
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
|
More in [viper documentation](https://github.com/spf13/viper#working-with-flags).
|
||||||
|
|
||||||
|
@ -300,31 +300,74 @@ rootCmd.PersistentFlags().StringVarP(&Region, "region", "r", "", "AWS region (re
|
||||||
rootCmd.MarkPersistentFlagRequired("region")
|
rootCmd.MarkPersistentFlagRequired("region")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Flag Groups
|
||||||
|
|
||||||
|
If you have different flags that must be provided together (e.g. if they provide the `--username` flag they MUST provide the `--password` flag as well) then
|
||||||
|
Cobra can enforce that requirement:
|
||||||
|
```go
|
||||||
|
rootCmd.Flags().StringVarP(&u, "username", "u", "", "Username (required if password is set)")
|
||||||
|
rootCmd.Flags().StringVarP(&pw, "password", "p", "", "Password (required if username is set)")
|
||||||
|
rootCmd.MarkFlagsRequiredTogether("username", "password")
|
||||||
|
```
|
||||||
|
|
||||||
|
You can also prevent different flags from being provided together if they represent mutually
|
||||||
|
exclusive options such as specifying an output format as either `--json` or `--yaml` but never both:
|
||||||
|
```go
|
||||||
|
rootCmd.Flags().BoolVar(&u, "json", false, "Output in JSON")
|
||||||
|
rootCmd.Flags().BoolVar(&pw, "yaml", false, "Output in YAML")
|
||||||
|
rootCmd.MarkFlagsMutuallyExclusive("json", "yaml")
|
||||||
|
```
|
||||||
|
|
||||||
|
In both of these cases:
|
||||||
|
- both local and persistent flags can be used
|
||||||
|
- **NOTE:** the group is only enforced on commands where every flag is defined
|
||||||
|
- a flag may appear in multiple groups
|
||||||
|
- a group may contain any number of flags
|
||||||
|
|
||||||
## Positional and Custom Arguments
|
## Positional and Custom Arguments
|
||||||
|
|
||||||
Validation of positional arguments can be specified using the `Args` field
|
Validation of positional arguments can be specified using the `Args` field of `Command`.
|
||||||
of `Command`.
|
|
||||||
|
|
||||||
The following validators are built in:
|
The following validators are built in:
|
||||||
|
|
||||||
- `NoArgs` - the command will report an error if there are any positional args.
|
- Number of arguments:
|
||||||
- `ArbitraryArgs` - the command will accept any args.
|
- `NoArgs` - report an error if there are any positional args.
|
||||||
- `OnlyValidArgs` - the command will report an error if there are any positional args that are not in the `ValidArgs` field of `Command`.
|
- `ArbitraryArgs` - accept any number of args.
|
||||||
- `MinimumNArgs(int)` - the command will report an error if there are not at least N positional args.
|
- `MinimumNArgs(int)` - report an error if less than N positional args are provided.
|
||||||
- `MaximumNArgs(int)` - the command will report an error if there are more than N positional args.
|
- `MaximumNArgs(int)` - report an error if more than N positional args are provided.
|
||||||
- `ExactArgs(int)` - the command will report an error if there are not exactly N positional args.
|
- `ExactArgs(int)` - report an error if there are not exactly N positional args.
|
||||||
- `ExactValidArgs(int)` - the command will report an error if there are not exactly N positional args OR if there are any positional args that are not in the `ValidArgs` field of `Command`
|
- `RangeArgs(min, max)` - report an error if the number of args is not between `min` and `max`.
|
||||||
- `RangeArgs(min, max)` - the command will report an error if the number of args is not between the minimum and maximum number of expected args.
|
- Content of the arguments:
|
||||||
|
- `OnlyValidArgs` - report an error if there are any positional args not specified in the `ValidArgs` field of `Command`, which can optionally be set to a list of valid values for positional args.
|
||||||
|
|
||||||
An example of setting the custom validator:
|
If `Args` is undefined or `nil`, it defaults to `ArbitraryArgs`.
|
||||||
|
|
||||||
|
Moreover, `MatchAll(pargs ...PositionalArgs)` enables combining existing checks with arbitrary other checks.
|
||||||
|
For instance, if you want to report an error if there are not exactly N positional args OR if there are any positional
|
||||||
|
args that are not in the `ValidArgs` field of `Command`, you can call `MatchAll` on `ExactArgs` and `OnlyValidArgs`, as
|
||||||
|
shown below:
|
||||||
|
|
||||||
|
```go
|
||||||
|
var cmd = &cobra.Command{
|
||||||
|
Short: "hello",
|
||||||
|
Args: MatchAll(ExactArgs(2), OnlyValidArgs),
|
||||||
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
fmt.Println("Hello, World!")
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
It is possible to set any custom validator that satisfies `func(cmd *cobra.Command, args []string) error`.
|
||||||
|
For example:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
var cmd = &cobra.Command{
|
var cmd = &cobra.Command{
|
||||||
Short: "hello",
|
Short: "hello",
|
||||||
Args: func(cmd *cobra.Command, args []string) error {
|
Args: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
// Optionally run one of the validators provided by cobra
|
||||||
return errors.New("requires a color argument")
|
if err := cobra.MinimumNArgs(1)(cmd, args); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
// Run the custom validation logic
|
||||||
if myapp.IsValidColor(args[0]) {
|
if myapp.IsValidColor(args[0]) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -404,7 +447,7 @@ a count and a string.`,
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
For a more complete example of a larger application, please checkout [Hugo](http://gohugo.io/).
|
For a more complete example of a larger application, please checkout [Hugo](https://gohugo.io/).
|
||||||
|
|
||||||
## Help Command
|
## Help Command
|
||||||
|
|
||||||
|
@ -419,28 +462,29 @@ create' is called. Every command will automatically have the '--help' flag adde
|
||||||
The following output is automatically generated by Cobra. Nothing beyond the
|
The following output is automatically generated by Cobra. Nothing beyond the
|
||||||
command and flag definitions are needed.
|
command and flag definitions are needed.
|
||||||
|
|
||||||
$ cobra help
|
$ cobra-cli help
|
||||||
|
|
||||||
Cobra is a CLI library for Go that empowers applications.
|
Cobra is a CLI library for Go that empowers applications.
|
||||||
This application is a tool to generate the needed files
|
This application is a tool to generate the needed files
|
||||||
to quickly create a Cobra application.
|
to quickly create a Cobra application.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
cobra [command]
|
cobra-cli [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
add Add a command to a Cobra Application
|
add Add a command to a Cobra Application
|
||||||
|
completion Generate the autocompletion script for the specified shell
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialize a Cobra Application
|
init Initialize a Cobra Application
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
||||||
--config string config file (default is $HOME/.cobra.yaml)
|
--config string config file (default is $HOME/.cobra.yaml)
|
||||||
-h, --help help for cobra
|
-h, --help help for cobra-cli
|
||||||
-l, --license string name of license for the project
|
-l, --license string name of license for the project
|
||||||
--viper use Viper for configuration (default true)
|
--viper use Viper for configuration
|
||||||
|
|
||||||
Use "cobra [command] --help" for more information about a command.
|
Use "cobra-cli [command] --help" for more information about a command.
|
||||||
|
|
||||||
|
|
||||||
Help is just a command like any other. There is no special logic or behavior
|
Help is just a command like any other. There is no special logic or behavior
|
||||||
|
@ -449,7 +493,7 @@ around it. In fact, you can provide your own if you want.
|
||||||
### Defining your own help
|
### Defining your own help
|
||||||
|
|
||||||
You can provide your own Help command or your own template for the default command to use
|
You can provide your own Help command or your own template for the default command to use
|
||||||
with following functions:
|
with the following functions:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
cmd.SetHelpCommand(cmd *Command)
|
cmd.SetHelpCommand(cmd *Command)
|
||||||
|
@ -468,22 +512,23 @@ showing the user the 'usage'.
|
||||||
You may recognize this from the help above. That's because the default help
|
You may recognize this from the help above. That's because the default help
|
||||||
embeds the usage as part of its output.
|
embeds the usage as part of its output.
|
||||||
|
|
||||||
$ cobra --invalid
|
$ cobra-cli --invalid
|
||||||
Error: unknown flag: --invalid
|
Error: unknown flag: --invalid
|
||||||
Usage:
|
Usage:
|
||||||
cobra [command]
|
cobra-cli [command]
|
||||||
|
|
||||||
Available Commands:
|
Available Commands:
|
||||||
add Add a command to a Cobra Application
|
add Add a command to a Cobra Application
|
||||||
|
completion Generate the autocompletion script for the specified shell
|
||||||
help Help about any command
|
help Help about any command
|
||||||
init Initialize a Cobra Application
|
init Initialize a Cobra Application
|
||||||
|
|
||||||
Flags:
|
Flags:
|
||||||
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
-a, --author string author name for copyright attribution (default "YOUR NAME")
|
||||||
--config string config file (default is $HOME/.cobra.yaml)
|
--config string config file (default is $HOME/.cobra.yaml)
|
||||||
-h, --help help for cobra
|
-h, --help help for cobra-cli
|
||||||
-l, --license string name of license for the project
|
-l, --license string name of license for the project
|
||||||
--viper use Viper for configuration (default true)
|
--viper use Viper for configuration
|
||||||
|
|
||||||
Use "cobra [command] --help" for more information about a command.
|
Use "cobra [command] --help" for more information about a command.
|
||||||
|
|
||||||
|
@ -602,7 +647,7 @@ Did you mean this?
|
||||||
Run 'hugo --help' for usage.
|
Run 'hugo --help' for usage.
|
||||||
```
|
```
|
||||||
|
|
||||||
Suggestions are automatic based on every subcommand registered and use an implementation of [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.
|
Suggestions are automatically generated based on existing subcommands and use an implementation of [Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance). Every registered command that matches a minimum distance of 2 (ignoring case) will be displayed as a suggestion.
|
||||||
|
|
||||||
If you need to disable suggestions or tweak the string distance in your command, use:
|
If you need to disable suggestions or tweak the string distance in your command, use:
|
||||||
|
|
||||||
|
@ -616,7 +661,8 @@ or
|
||||||
command.SuggestionsMinimumDistance = 1
|
command.SuggestionsMinimumDistance = 1
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also explicitly set names for which a given command will be suggested using the `SuggestFor` attribute. This allows suggestions for strings that are not close in terms of string distance, but makes sense in your set of commands and for some which you don't want aliases. Example:
|
You can also explicitly set names for which a given command will be suggested using the `SuggestFor` attribute. This allows suggestions for strings that are not close in terms of string distance, but make sense in your set of commands but for which
|
||||||
|
you don't want aliases. Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
$ kubectl remove
|
$ kubectl remove
|
||||||
|
@ -635,3 +681,7 @@ Cobra can generate documentation based on subcommands, flags, etc. Read more abo
|
||||||
## Generating shell completions
|
## Generating shell completions
|
||||||
|
|
||||||
Cobra can generate a shell-completion file for the following shells: bash, zsh, fish, PowerShell. If you add more information to your commands, these completions can be amazingly powerful and flexible. Read more about it in [Shell Completions](shell_completions.md).
|
Cobra can generate a shell-completion file for the following shells: bash, zsh, fish, PowerShell. If you add more information to your commands, these completions can be amazingly powerful and flexible. Read more about it in [Shell Completions](shell_completions.md).
|
||||||
|
|
||||||
|
## Providing Active Help
|
||||||
|
|
||||||
|
Cobra makes use of the shell-completion system to define a framework allowing you to provide Active Help to your users. Active Help are messages (hints, warnings, etc) printed as the program is being used. Read more about it in [Active Help](active_help.md).
|
||||||
|
|
|
@ -1,3 +1,17 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
package cobra
|
package cobra
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -75,7 +89,7 @@ func genZshComp(buf io.StringWriter, name string, includeDesc bool) {
|
||||||
if !includeDesc {
|
if !includeDesc {
|
||||||
compCmd = ShellCompNoDescRequestCmd
|
compCmd = ShellCompNoDescRequestCmd
|
||||||
}
|
}
|
||||||
WriteStringAndCheck(buf, fmt.Sprintf(`#compdef _%[1]s %[1]s
|
WriteStringAndCheck(buf, fmt.Sprintf(`#compdef %[1]s
|
||||||
|
|
||||||
# zsh completion for %-36[1]s -*- shell-script -*-
|
# zsh completion for %-36[1]s -*- shell-script -*-
|
||||||
|
|
||||||
|
@ -163,7 +177,24 @@ _%[1]s()
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local activeHelpMarker="%[8]s"
|
||||||
|
local endIndex=${#activeHelpMarker}
|
||||||
|
local startIndex=$((${#activeHelpMarker}+1))
|
||||||
|
local hasActiveHelp=0
|
||||||
while IFS='\n' read -r comp; do
|
while IFS='\n' read -r comp; do
|
||||||
|
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
|
||||||
|
if [ "${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
|
||||||
|
__%[1]s_debug "ActiveHelp found: $comp"
|
||||||
|
comp="${comp[$startIndex,-1]}"
|
||||||
|
if [ -n "$comp" ]; then
|
||||||
|
compadd -x "${comp}"
|
||||||
|
__%[1]s_debug "ActiveHelp will need delimiter"
|
||||||
|
hasActiveHelp=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "$comp" ]; then
|
if [ -n "$comp" ]; then
|
||||||
# If requested, completions are returned with a description.
|
# If requested, completions are returned with a description.
|
||||||
# The description is preceded by a TAB character.
|
# The description is preceded by a TAB character.
|
||||||
|
@ -171,7 +202,7 @@ _%[1]s()
|
||||||
# We first need to escape any : as part of the completion itself.
|
# We first need to escape any : as part of the completion itself.
|
||||||
comp=${comp//:/\\:}
|
comp=${comp//:/\\:}
|
||||||
|
|
||||||
local tab=$(printf '\t')
|
local tab="$(printf '\t')"
|
||||||
comp=${comp//$tab/:}
|
comp=${comp//$tab/:}
|
||||||
|
|
||||||
__%[1]s_debug "Adding completion: ${comp}"
|
__%[1]s_debug "Adding completion: ${comp}"
|
||||||
|
@ -180,6 +211,17 @@ _%[1]s()
|
||||||
fi
|
fi
|
||||||
done < <(printf "%%s\n" "${out[@]}")
|
done < <(printf "%%s\n" "${out[@]}")
|
||||||
|
|
||||||
|
# Add a delimiter after the activeHelp statements, but only if:
|
||||||
|
# - there are completions following the activeHelp statements, or
|
||||||
|
# - file completion will be performed (so there will be choices after the activeHelp)
|
||||||
|
if [ $hasActiveHelp -eq 1 ]; then
|
||||||
|
if [ ${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
|
||||||
|
__%[1]s_debug "Adding activeHelp delimiter"
|
||||||
|
compadd -x "--"
|
||||||
|
hasActiveHelp=0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
|
||||||
__%[1]s_debug "Activating nospace."
|
__%[1]s_debug "Activating nospace."
|
||||||
noSpace="-S ''"
|
noSpace="-S ''"
|
||||||
|
@ -202,7 +244,7 @@ _%[1]s()
|
||||||
_arguments '*:filename:'"$filteringCmd"
|
_arguments '*:filename:'"$filteringCmd"
|
||||||
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
|
||||||
# File completion for directories only
|
# File completion for directories only
|
||||||
local subDir
|
local subdir
|
||||||
subdir="${completions[1]}"
|
subdir="${completions[1]}"
|
||||||
if [ -n "$subdir" ]; then
|
if [ -n "$subdir" ]; then
|
||||||
__%[1]s_debug "Listing directories in $subdir"
|
__%[1]s_debug "Listing directories in $subdir"
|
||||||
|
@ -254,5 +296,6 @@ if [ "$funcstack[1]" = "_%[1]s" ]; then
|
||||||
fi
|
fi
|
||||||
`, name, compCmd,
|
`, name, compCmd,
|
||||||
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
ShellCompDirectiveError, ShellCompDirectiveNoSpace, ShellCompDirectiveNoFileComp,
|
||||||
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs))
|
ShellCompDirectiveFilterFileExt, ShellCompDirectiveFilterDirs,
|
||||||
|
activeHelpMarker))
|
||||||
}
|
}
|
||||||
|
|
33
zsh_completions_test.go
Normal file
33
zsh_completions_test.go
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2013-2022 The Cobra Authors
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
// you may not use this file except in compliance with the License.
|
||||||
|
// You may obtain a copy of the License at
|
||||||
|
//
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
//
|
||||||
|
// Unless required by applicable law or agreed to in writing, software
|
||||||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
// See the License for the specific language governing permissions and
|
||||||
|
// limitations under the License.
|
||||||
|
|
||||||
|
package cobra
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestZshCompletionWithActiveHelp(t *testing.T) {
|
||||||
|
c := &Command{Use: "c", Run: emptyRun}
|
||||||
|
|
||||||
|
buf := new(bytes.Buffer)
|
||||||
|
assertNoErr(t, c.GenZshCompletion(buf))
|
||||||
|
output := buf.String()
|
||||||
|
|
||||||
|
// check that active help is not being disabled
|
||||||
|
activeHelpVar := activeHelpEnvVar(c.Name())
|
||||||
|
checkOmit(t, output, fmt.Sprintf("%s=0", activeHelpVar))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue