Skip to content

Commit

Permalink
*: fix cli stdin (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
xhebox authored Oct 24, 2022
1 parent ff1f40a commit 544b0cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 2 additions & 4 deletions lib/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package cli

import (
"fmt"
"io"
"net/http"
"os"

Expand All @@ -40,15 +39,14 @@ func getConfigCmd(ctx *Context, pathSuffix string) *cobra.Command {
}
input := setProxy.Flags().String("input", "", "specify the input json file for proxy config")
setProxy.RunE = func(cmd *cobra.Command, args []string) error {
var b io.Reader
b := cmd.InOrStdin()
if *input != "" {
f, err := os.Open(*input)
if err != nil {
return err
}
defer f.Close()
} else {
b = os.Stdin
b = f
}

resp, err := doRequest(cmd.Context(), ctx, http.MethodPut, path, b)
Expand Down
4 changes: 2 additions & 2 deletions lib/cli/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,10 @@ func GetNamespaceCmd(ctx *Context) *cobra.Command {
putNamespace := &cobra.Command{
Use: "put",
}
ns := putNamespace.Flags().String("ns", "-", "file")
ns := putNamespace.Flags().String("ns", "", "file, or stdin")
putNamespace.RunE = func(cmd *cobra.Command, _ []string) error {
in := cmd.InOrStdin()
if *ns != "-" {
if *ns != "" {
f, err := os.Open(*ns)
if err != nil {
return err
Expand Down

0 comments on commit 544b0cc

Please sign in to comment.