From 7b84d794059aa1523a89044041982bde497252f9 Mon Sep 17 00:00:00 2001 From: pfeodrippe Date: Thu, 25 May 2017 01:13:00 -0300 Subject: [PATCH 1/3] check if the config comes from pipe and stat size > 0 --- cmd/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/config.go b/cmd/config.go index a2ff3a7d..ae391503 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -244,7 +244,7 @@ func (d *DeisCmd) ConfigPush(appID, fileName string) error { var contents []byte - if (stat.Mode() & os.ModeCharDevice) == 0 { + if (stat.Mode()&os.ModeNamedPipe) == 0 && stat.Size() > 0 { buffer := new(bytes.Buffer) buffer.ReadFrom(os.Stdin) contents = buffer.Bytes() From 6c27d5684bd8714194ecc3749480862fc8e6c701 Mon Sep 17 00:00:00 2001 From: pfeodrippe Date: Fri, 26 May 2017 09:39:49 -0300 Subject: [PATCH 2/3] [WIP] debugging --- .DS_Store | Bin 0 -> 6148 bytes cmd/config.go | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5c5408557b518a2d9f5644b430e82eecbe5f8753 GIT binary patch literal 6148 zcmeHKI|>3Z5S{S@f{mqRuHX%V=m|W47J>+(;IH1wb9pr1e41sk(?WRzlb1~9CFB)5 zJ0ha<+jb^05s?wxP#!jP&GyYZ*2{}dSygLxhmpaMUyfPEhd+^{A#f&S^h;4J`ffUq0p-b( 0 { - buffer := new(bytes.Buffer) - buffer.ReadFrom(os.Stdin) - contents = buffer.Bytes() - } else { + d.Print("os - ModeCharDevice: ") + d.Println(os.ModeCharDevice) + d.Print("os - ModeNamedPipe: ") + d.Println(os.ModeNamedPipe) + d.Print("stat - Mode: ") + d.Println(stat.Mode()) + d.Print("stat - Size: ") + d.Println(stat.Size()) + d.Print("stat - Flag: ") + d.Println(stat.Mode()&os.ModeNamedPipe == 0) + if stat.Size() <= 0 || stat.Mode()&os.ModeNamedPipe == 0 { + d.Println("NOT STDIN!") contents, err = ioutil.ReadFile(fileName) if err != nil { return err } + } else { + d.Println("STDIN!") + buffer := new(bytes.Buffer) + buffer.ReadFrom(os.Stdin) + contents = buffer.Bytes() } file := strings.Split(string(contents), "\n") From 806f3ad395681c48943ff6b3e910e8d557d6eabd Mon Sep 17 00:00:00 2001 From: pfeodrippe Date: Sat, 27 May 2017 02:09:24 -0300 Subject: [PATCH 3/3] add verbose option to config:push and fix IO redirection of the form 'deis config:push -a app-name < deis-env' --- cmd/cmd.go | 2 +- cmd/config.go | 33 +++++++++++++++------------------ parser/config.go | 9 ++++++--- parser/config_test.go | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 3af972df..82cb560a 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -40,7 +40,7 @@ type Commander interface { ConfigSet(string, []string) error ConfigUnset(string, []string) error ConfigPull(string, bool, bool) error - ConfigPush(string, string) error + ConfigPush(string, string, bool) error DomainsList(string, int) error DomainsAdd(string, string) error DomainsRemove(string, string) error diff --git a/cmd/config.go b/cmd/config.go index 46ba5b07..24cdbfc9 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -235,7 +235,7 @@ func (d *DeisCmd) ConfigPull(appID string, interactive bool, overwrite bool) err } // ConfigPush pushes an app's config from a file. -func (d *DeisCmd) ConfigPush(appID, fileName string) error { +func (d *DeisCmd) ConfigPush(appID, fileName string, verbose bool) error { stat, err := os.Stdin.Stat() if err != nil { @@ -243,28 +243,25 @@ func (d *DeisCmd) ConfigPush(appID, fileName string) error { } var contents []byte - d.Print("os - ModeCharDevice: ") - d.Println(os.ModeCharDevice) - d.Print("os - ModeNamedPipe: ") - d.Println(os.ModeNamedPipe) - d.Print("stat - Mode: ") - d.Println(stat.Mode()) - d.Print("stat - Size: ") - d.Println(stat.Size()) - d.Print("stat - Flag: ") - d.Println(stat.Mode()&os.ModeNamedPipe == 0) - if stat.Size() <= 0 || stat.Mode()&os.ModeNamedPipe == 0 { - d.Println("NOT STDIN!") + if ((stat.Mode()&os.ModeNamedPipe) != 0 || stat.Size() > 0) && fileName == ".no-file" { + if verbose { + d.Println("Getting input from stdin") + } + buffer := new(bytes.Buffer) + buffer.ReadFrom(os.Stdin) + contents = buffer.Bytes() + } else { + if verbose { + d.Println("Not getting input from stdin") + } + if fileName == ".no-file" { + fileName = ".env" + } contents, err = ioutil.ReadFile(fileName) if err != nil { return err } - } else { - d.Println("STDIN!") - buffer := new(bytes.Buffer) - buffer.ReadFrom(os.Stdin) - contents = buffer.Bytes() } file := strings.Split(string(contents), "\n") diff --git a/parser/config.go b/parser/config.go index 364edb10..abfb94ed 100644 --- a/parser/config.go +++ b/parser/config.go @@ -176,9 +176,11 @@ Usage: deis config:push [options] Options: -a --app= - the uniquely identifiable name for the application. + The uniquely identifiable name for the application. -p , --path= - a path leading to an environment file [default: .env] + A path leading to an environment file [default: .no-file] + -v --verbose + Show debug output ` args, err := docopt.Parse(usage, argv, true, "", false, true) @@ -189,6 +191,7 @@ Options: app := safeGetValue(args, "--app") path := safeGetValue(args, "--path") + verbose := args["--verbose"].(bool) - return cmdr.ConfigPush(app, path) + return cmdr.ConfigPush(app, path, verbose) } diff --git a/parser/config_test.go b/parser/config_test.go index fc7342cb..28be852e 100644 --- a/parser/config_test.go +++ b/parser/config_test.go @@ -28,7 +28,7 @@ func (d FakeDeisCmd) ConfigPull(string, bool, bool) error { return errors.New("config:pull") } -func (d FakeDeisCmd) ConfigPush(string, string) error { +func (d FakeDeisCmd) ConfigPush(string, string, bool) error { return errors.New("config:push") }