Skip to content

Commit

Permalink
initual upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasCarioca committed Oct 4, 2021
0 parents commit b301ed0
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/gocli.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions cli/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package cli

//Command interface that cli commands should conform to
type Command interface {
Run() error
}
33 changes: 33 additions & 0 deletions cli/pipe-reader.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cli

import (
"bufio"
"errors"
"io"
"os"
)

// ReadPipe reads in the content that is piped to the cli and returns it as a string
func ReadPipe() (string, error) {
info, err := os.Stdin.Stat()
if err != nil {
panic(err)
}

if info.Mode()&os.ModeCharDevice != 0 || info.Size() <= 0 {
return "", errors.New("the command is intended to work with pipes")
}

reader := bufio.NewReader(os.Stdin)
var output []rune

for {
input, _, err := reader.ReadRune()
if err != nil && err == io.EOF {
break
}
output = append(output, input)
}

return string(output), nil
}
11 changes: 11 additions & 0 deletions cli/test-helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package cli

import (
"os"
"strings"
)

//MockCLICall mock arguments passed to the CLI for tests
func MockCLICall(cmd string) {
os.Args = strings.SplitAfter(cmd, " ")
}
14 changes: 14 additions & 0 deletions cli/version-comand.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cli

import "fmt"

//VersionCommand used to retrieve the current version of the terraform cli
type VersionCommand struct {
Version string
}

//Run run the command
func (c *VersionCommand) Run() error {
fmt.Printf("Current version: v%s\n", c.Version)
return nil
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module gocli

go 1.16

0 comments on commit b301ed0

Please sign in to comment.