Skip to content

Commit

Permalink
OS-10 | Use cobra-commander (#3)
Browse files Browse the repository at this point in the history
* OS-10 | Use cobra-commander

* fix lints

* Update README.md

* GH actions
  • Loading branch information
Hakan Kurtulus authored Jun 5, 2021
1 parent bbbce19 commit 98c4b48
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 169 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Code Check

on:
push:
pull_request:

jobs:
test:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ lint:
go vet ./...
go get github.com/golangci/golangci-lint/cmd/[email protected]
@golangci-lint --version
golangci-lint run --fix
golangci-lint run
go get -u golang.org/x/lint/golint
golint -set_exit_status ./...

Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ SSH Key Manager for Bitwarden and 1Password
</p>

```shell
CLI command to manage SSH keys stored on Bitwarden and 1Password
CLI command to automatically unseal Vault

Usage:
ssh-manager [command]
vault-unseal [command]

Available Commands:
add Add SSH key to given provider.
Expand All @@ -30,11 +30,11 @@ Available Commands:
version Print the version/build number

Flags:
-h, --help help for ssh-manager
--logLevel string Set the logging level. One of: debug|info|warn|error (default "info")

Use "ssh-manager [command] --help" for more information about a command.
-h, --help help for vault-unseal
--logFormat string Set the logging format. One of: text|json (default "text") (default "text")
--logLevel string Set the logging level. One of: debug|info|warn|error (default "info")

Use "vault-unseal [command] --help" for more information about a command.
```

## Installation
Expand Down
17 changes: 0 additions & 17 deletions cmd/helpers.go

This file was deleted.

61 changes: 0 additions & 61 deletions cmd/main.go

This file was deleted.

42 changes: 0 additions & 42 deletions cmd/main_test.go

This file was deleted.

12 changes: 0 additions & 12 deletions cmd/version_test.go

This file was deleted.

5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@ module github.com/omegion/ssh-manager
go 1.16

require (
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/omegion/cobra-commander v0.3.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
k8s.io/utils v0.0.0-20210521133846-da695404a2bc
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/omegion/cobra-commander v0.3.0 h1:TDfiWY/SQ+mLMQgyrT+JaYsYxYFctyjalp8E3lgZCH0=
github.com/omegion/cobra-commander v0.3.0/go.mod h1:qRXZO0ajS6RP8iydGEViTVaPAflLBpdzUPVm648KLQQ=
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down Expand Up @@ -239,8 +241,8 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
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-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1 h1:lCnv+lfrU9FRPGf8NeRuWAAPjNnema5WtBinMgs1fD8=
golang.org/x/sys v0.0.0-20210521203332-0cec03c779c1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210603125802-9665404d3644 h1:CA1DEQ4NdKphKeL70tvsWNdT5oFh1lOjihRcEDROi0I=
golang.org/x/sys v0.0.0-20210603125802-9665404d3644/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
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=
Expand Down
22 changes: 19 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,30 @@ package main
import (
"os"

commander "github.com/omegion/cobra-commander"
"github.com/spf13/cobra"

"github.com/omegion/ssh-manager/cmd"
)

func main() {
commander := cmd.NewCommander()
commander.Setup()
root := &cobra.Command{
Use: "vault-unseal",
Short: "Vault Auto Unseal",
Long: "CLI command to automatically unseal Vault",
SilenceUsage: true,
}

c := commander.NewCommander(root).
SetCommand(
cmd.Version(),
cmd.Get(),
cmd.Add(),
cmd.List(),
).
Init()

if err := commander.Root.Execute(); err != nil {
if err := c.Execute(); err != nil {
os.Exit(1)
}
}
30 changes: 10 additions & 20 deletions test/fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,30 @@ package test

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestLoadFixture_found(t *testing.T) {
data, err := LoadFixture("data")
if err != nil {
t.Errorf("TestLoadFixture_found should find the 'data' file")
}

expected := "yey\n"
if string(data) != expected {
t.Errorf("Expected file content: %s, got: %s", expected, data)
}

assert.NoError(t, err)
assert.Equal(t, "yey\n", string(data))
}

func TestLoadFixture_notFound(t *testing.T) {
data, err := LoadFixture("nodata")
if err == nil {
t.Errorf("TestLoadFixture_notFound should not find the 'nodata' file")
}

expected := ""
if string(data) != expected {
t.Errorf("Expected file content: %s, got: %s", expected, data)
}

assert.Error(t, err)
assert.Equal(t, "", string(data))
}

func TestMust_noError(t *testing.T) {
input := []byte("Yey")
expected := "Yey"

output := Must(input, nil)
if string(output) != expected {
t.Errorf("Must() = %v, want %v", output, expected)
}

assert.Equal(t, "Yey", string(output))
}

func TestMust_hasError(t *testing.T) {
Expand Down

0 comments on commit 98c4b48

Please sign in to comment.