Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Adding version command support to DCE-CLI #68

Merged
merged 3 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## vNext
- Added `version` command to support viewing the current release version of the running binary

## v0.4.0
- Added `--tf-init-options` and `--tf-apply-options` for greater control over underlying provisioner
- Added `--save-options` flag to persist the `--tf-init-options` and `--tf-apply-options` to the
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
VERSION := $(shell git describe --always --long --dirty)

all: mocks test build

# Generate client code from swagger in a local dce repo (make openapi DCE_REPO=/path/to/dce)
Expand Down Expand Up @@ -31,7 +33,7 @@ test_unit:
go test -count=1 -v ./tests/unit/

build:
go build .
go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=${VERSION}" .

.PHONY: docs
docs:
Expand Down
12 changes: 8 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ pool:

steps:

- bash: |
GIT_VERSION="$(git describe --always --long --dirty)"
echo "##vso[task.setvariable variable=VERSION]${GIT_VERSION}"

- task: GoTool@0
inputs:
version: '1.13'
Expand All @@ -36,7 +40,7 @@ steps:
- script: |
set -x
# etcd depdendency bug workaround. See commends in go.mod for more details.
go build -v .
go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v .
sudo rm /home/vsts/go/pkg/mod/github.com/coreos/etcd@v3.3.10+incompatible/client/keys.generated.go
make test
displayName: 'Run tests'
Expand All @@ -46,19 +50,19 @@ steps:
mkdir dist && cd dist
# zip for windows and calculate sha256 hash
WINFILE=dce_windows_amd64.zip
env GOOS=windows GOARCH=amd64 go build -v -o ./dce ..
env GOOS=windows GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce ..
zip -m $WINFILE ./dce
WINSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $WINFILE); echo "${ADDR[0]}")

# zip for linux and calculate sha256 hash
LINFILE=dce_linux_amd64.zip
env GOOS=linux GOARCH=amd64 go build -v -o ./dce ..
env GOOS=linux GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce ..
zip -m $LINFILE ./dce
LINSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $LINFILE); echo "${ADDR[0]}")

# zip for mac and calculate sha256 hash
MACFILE=dce_darwin_amd64.zip
env GOOS=darwin GOARCH=amd64 go build -v -o ./dce ..
env GOOS=darwin GOARCH=amd64 go build -ldflags "-X github.com/Optum/dce-cli/cmd.version=$(VERSION)" -v -o ./dce ..
zip -m $MACFILE ./dce
MACSHA=$(IFS=' '; read -ra ADDR <<< $(sha256sum $MACFILE); echo "${ADDR[0]}")
cat> ../release.md <<- EOF
Expand Down
11 changes: 10 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ func preRun(cmd *cobra.Command, args []string) error {
return err
}

// Check if the requested command is for a version check
// If it is, return here, as no creds are needed

if cmd.Name() == versionCmd.Name() {
return nil
}

// Check if the user has valid creds,
// otherwise require authentication
creds := Util.AWSSession.Config.Credentials
Expand Down Expand Up @@ -129,7 +136,9 @@ func onInit(cmd *cobra.Command, args []string) error {
// If config file does not exist,
// run the `dce init` command
if !fsUtil.IsExistingFile(cfgFile) {
if cmd.Name() != initCmd.Name() {
if cmd.Name() == versionCmd.Name() {
return nil
} else if cmd.Name() != initCmd.Name() {
return errors.New("Config file not found. Please type 'dce init' to generate one.")
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"strings"
)

var version string

func init() {
RootCmd.AddCommand(versionCmd)
}

var versionCmd = &cobra.Command{
Use: "version",
Short: "View the running version of dce-cli",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
shortVersion := strings.Split(version, "-")[0]
finalVersion := strings.Replace(shortVersion, "v", "", 1)
fmt.Println(finalVersion)
},
}
3 changes: 2 additions & 1 deletion docs/dce.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ Disposable Cloud Environment (DCE)
* [dce leases](dce_leases.md) - Manage dce leases
* [dce system](dce_system.md) - Deploy and configure the DCE system
* [dce usage](dce_usage.md) - View lease budget information
* [dce version](dce_version.md) - View the running version of dce-cli

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Manage dce accounts
* [dce accounts list](dce_accounts_list.md) - list accounts
* [dce accounts remove](dce_accounts_remove.md) - Remove an account from the accounts pool.

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_accounts_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ dce accounts add [flags]

* [dce accounts](dce_accounts.md) - Manage dce accounts

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_accounts_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce accounts describe [Accound ID] [flags]

* [dce accounts](dce_accounts.md) - Manage dce accounts

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_accounts_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce accounts list [flags]

* [dce accounts](dce_accounts.md) - Manage dce accounts

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_accounts_remove.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce accounts remove [Account ID] [flags]

* [dce accounts](dce_accounts.md) - Manage dce accounts

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce auth [flags]

* [dce](dce.md) - Disposable Cloud Environment (DCE)

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_init.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce init [flags]

* [dce](dce.md) - Disposable Cloud Environment (DCE)

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ Manage dce leases
* [dce leases list](dce_leases_list.md) - List leases using various query filters.
* [dce leases login](dce_leases_login.md) - Login to a leased DCE account. (Sets AWS CLI credentials if used with no flags)

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ dce leases create [flags]

* [dce leases](dce_leases.md) - Manage dce leases

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ dce leases describe [Lease ID] [flags]

* [dce leases](dce_leases.md) - Manage dce leases

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases_end.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ dce leases end [flags]

* [dce leases](dce_leases.md) - Manage dce leases

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ dce leases list [flags]

* [dce leases](dce_leases.md) - Manage dce leases

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_leases_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ dce leases login [Lease ID] [flags]

* [dce leases](dce_leases.md) - Manage dce leases

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ Deploy and configure the DCE system
* [dce](dce.md) - Disposable Cloud Environment (DCE)
* [dce system deploy](dce_system_deploy.md) - Deploy DCE to a new master account

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_system_deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,4 @@ dce system deploy [flags]

* [dce system](dce_system.md) - Deploy and configure the DCE system

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
2 changes: 1 addition & 1 deletion docs/dce_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ dce usage [flags]

* [dce](dce.md) - Disposable Cloud Environment (DCE)

###### Auto generated by spf13/cobra on 21-Jan-2020
###### Auto generated by spf13/cobra on 5-Feb-2020
29 changes: 29 additions & 0 deletions docs/dce_version.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## dce version

View the running version of dce-cli

### Synopsis

View the running version of dce-cli

```
dce version [flags]
```

### Options

```
-h, --help help for version
```

### Options inherited from parent commands

```
--config string config file (default is "$HOME/.dce/config.yaml")
```

### SEE ALSO

* [dce](dce.md) - Disposable Cloud Environment (DCE)

###### Auto generated by spf13/cobra on 5-Feb-2020
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,16 @@ require (
github.com/gogo/protobuf v1.2.1 // indirect
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef // indirect
github.com/grpc-ecosystem/grpc-gateway v1.9.0 // indirect
github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f
github.com/hashicorp/terraform v0.12.10
github.com/hashicorp/terraform v0.12.10 // indirect
github.com/manifoldco/promptui v0.3.2
github.com/mholt/archiver v3.1.1+incompatible
github.com/mitchellh/cli v1.0.0
github.com/mitchellh/go-homedir v1.1.0
github.com/nwaples/rardecode v1.0.0 // indirect
github.com/pierrec/lz4 v2.3.0+incompatible // indirect
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4
github.com/pkg/errors v0.8.0
github.com/prometheus/client_golang v0.9.3 // indirect
github.com/shurcooL/githubv4 v0.0.0-20191006152017-6d1ea27df521
github.com/shurcooL/githubv4 v0.0.0-20191006152017-6d1ea27df521 // indirect
github.com/shurcooL/graphql v0.0.0-20181231061246-d48a9a75455f // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.5
Expand All @@ -56,7 +54,6 @@ require (
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/thriftrw v1.20.2
go.uber.org/zap v1.10.0 // indirect
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
gopkg.in/yaml.v2 v2.2.4
)
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nicksnyder/go-i18n v2.0.3+incompatible h1:XCCaWsCoy4KlWkhOr+63dkv6oJmitJ573uJqDBAiFiQ=
Copy link
Contributor

Choose a reason for hiding this comment

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

@drmmarsunited do you know where this sum came from. We are trying to track it down and can't figure it out. The go.mod just has package removals and comment changes to the /indirect which doesn't seem like it should add something.

Copy link
Author

Choose a reason for hiding this comment

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

No, I saw that as well. I didn't do anything special to pull in the code, just ran a go get. I can try to refork and do it from scratch and see if it comes up again?

Copy link
Contributor

Choose a reason for hiding this comment

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

we are trying a few things here too but haven't been able to track it down.

Copy link
Author

Choose a reason for hiding this comment

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

Let me try cloning to a whole new directory and populating the modules. I'll let you know if I see the sum change or not.

Copy link
Author

Choose a reason for hiding this comment

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

@kddejong So if I clone the master branch of my fork (which is unchanged from upstream), and I run go get in the newly cloned folder, the sum changes with this same line.

github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/nwaples/rardecode v1.0.0 h1:r7vGuS5akxOnR4JQSkko62RJ1ReCMXxQRPtxsiFMBOs=
Expand Down