-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b301ed0
Showing
9 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, " ") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module gocli | ||
|
||
go 1.16 |