⚡ Adds id and options string flags
This commit is contained in:
parent
f64f02cfd9
commit
e9065fb654
@ -56,11 +56,35 @@ func main() {
|
|||||||
{
|
{
|
||||||
Name: "clients",
|
Name: "clients",
|
||||||
Usage: "fetch all clients",
|
Usage: "fetch all clients",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "id",
|
||||||
|
Usage: "optional id of a client to fetch",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: clients,
|
Action: clients,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "logs",
|
Name: "logs",
|
||||||
Usage: "fetch all/specific logs",
|
Usage: "fetch all/specific logs",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "id",
|
||||||
|
Usage: "optional id of a client to log",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "date",
|
||||||
|
Usage: "optional date of the log, id required, in ISO8601 date format",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "skip",
|
||||||
|
Usage: "optional skip bytes in log file",
|
||||||
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "take",
|
||||||
|
Usage: "optional take bytes from log file",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: logs,
|
Action: logs,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -72,13 +96,20 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func clients(context.Context, *cli.Command) error {
|
func clients(ctx context.Context, cmd *cli.Command) error {
|
||||||
err := load()
|
err := load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/admin/clients", server)
|
var url string
|
||||||
|
id := cmd.String("id")
|
||||||
|
if id != "" {
|
||||||
|
url = fmt.Sprintf("%s/admin/clients/%s", server, id)
|
||||||
|
} else {
|
||||||
|
url = fmt.Sprintf("%s/admin/clients", server)
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -100,13 +131,38 @@ func clients(context.Context, *cli.Command) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func logs(context.Context, *cli.Command) error {
|
func logs(ctx context.Context, cmd *cli.Command) error {
|
||||||
err := load()
|
err := load()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
url := fmt.Sprintf("%s/admin/logs", server)
|
var url string
|
||||||
|
id := cmd.String("id")
|
||||||
|
if id != "" {
|
||||||
|
params := map[string]string{
|
||||||
|
"date": cmd.String("date"),
|
||||||
|
"skip": cmd.String("skip"),
|
||||||
|
"take": cmd.String("take"),
|
||||||
|
}
|
||||||
|
paramsStr := ""
|
||||||
|
for k, v := range params {
|
||||||
|
if v == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if paramsStr == "" {
|
||||||
|
paramsStr = fmt.Sprintf("?%s=%s", k, v)
|
||||||
|
} else {
|
||||||
|
paramsStr += fmt.Sprintf("&%s=%s", k, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
url = fmt.Sprintf("%s/admin/%s/logs%s", server, id, paramsStr)
|
||||||
|
} else {
|
||||||
|
url = fmt.Sprintf("%s/admin/logs", server)
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user