Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add egctl edit, egctl logs, update egctl create cmd #1067

Merged
merged 15 commits into from
Aug 31, 2023
Prev Previous commit
Next Next commit
add verbose flag for egctl describe
  • Loading branch information
suchen-sci committed Aug 18, 2023
commit c52711644eabc18d25ecf2800377d0276564f991
2 changes: 2 additions & 0 deletions cmd/client/commandv2/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func DescribeCmd() *cobra.Command {
{Desc: "Describe all instances in that resource", Command: "egctl describe <resource>"},
{Desc: "Describe a httpserver", Command: "egctl describe httpserver <name>"},
{Desc: "Describe all pipelines", Command: "egctl describe pipeline"},
{Desc: "Describe pipelines with verbose information", Command: "egctl describe pipeline -v"},
{Desc: "Describe all members", Command: "egctl describe member"},
{Desc: "Describe a customdata kind", Command: "egctl describe customdatakind <name>"},
{Desc: "Describe a customdata of given kind", Command: "egctl describe customdata <kind> <name>"},
Expand All @@ -45,6 +46,7 @@ func DescribeCmd() *cobra.Command {
Example: createMultiExample(examples),
Run: describeCmdRun,
}
cmd.Flags().BoolVarP(&general.CmdGlobalFlags.Verbose, "verbose", "v", false, "Print verbose information")
return cmd
}

Expand Down
3 changes: 3 additions & 0 deletions cmd/client/general/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type (
ForceTLS bool
InsecureSkipVerify bool
OutputFormat string

// following are some general flags. Can be used by all commands. But not all commands use them.
Verbose bool
}

// APIErr is the standard return of error.
Expand Down
9 changes: 8 additions & 1 deletion cmd/client/general/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ func DurationMostSignificantUnit(d time.Duration) string {
// For example, if specials is ["name", "kind", "", "filters"]
// then, "name", "kind" will in group one, and "filters" will in group two, others will in group three.
func PrintMapInterface(maps []map[string]interface{}, fronts []string, backs []string) {
cutLine := func(line string) string {
if CmdGlobalFlags.Verbose || len(line) < 50 {
return line
}
return line[0:50] + "..."
}

printKV := func(k string, v interface{}) {
value, err := codectool.MarshalYAML(v)
if err != nil {
Expand All @@ -142,7 +149,7 @@ func PrintMapInterface(maps []map[string]interface{}, fronts []string, backs []s
lines := strings.Split(string(value), "\n")
lines = lines[0 : len(lines)-1]
if len(lines) == 1 {
fmt.Printf("%s: %s\n", Capitalize(k), lines[0])
fmt.Printf("%s: %s\n", Capitalize(k), cutLine(lines[0]))
return
}
fmt.Printf("%s:\n", Capitalize(k))
Expand Down
3 changes: 3 additions & 0 deletions cmd/client/resources/customdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package resources
import (
"fmt"
"net/http"
"os"
"strings"

"github.com/megaease/easegress/v2/cmd/client/general"
Expand Down Expand Up @@ -210,6 +211,7 @@ func editCustomDataBatch(cmd *cobra.Command, args *general.ArgInfo) error {
if err != nil {
return getErr(editErrWithPath(err, filePath))
}
os.Remove(filePath)
return nil
}

Expand Down Expand Up @@ -250,6 +252,7 @@ func editCustomDataItem(cmd *cobra.Command, args *general.ArgInfo) error {
if err != nil {
return getErr(editErrWithPath(err, filePath))
}
os.Remove(filePath)
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions doc/egctl-cheat-sheet.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ egctl apply -f httpserver-demo-version2.yaml # update HTTPServer resource
egctl apply -f cdk-demo2.yaml # udpate CustomDataKind resource
```

## Editing resources
```
egctl edit httpserver httpserver-demo # edit httpserver with name httpserver-demo
egctl edit customdata cdk-demo # batch edit custom data with kind cdk-demo
egctl edit customdata cdk-demo data1 # edit custom data data1 of kind cdk-demo
```

## Deleting resources
```
egctl delete httpserver httpserver-demo # delete HTTPServer resource with name "httpserver-demo"
Expand Down