2023-02-28 15:50:35 +01:00
|
|
|
package agent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/client"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/command/client/apierr"
|
|
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
|
|
|
|
"forge.cadoles.com/Cadoles/emissary/internal/format"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
func CountCommand() *cli.Command {
|
|
|
|
return &cli.Command{
|
|
|
|
Name: "count",
|
|
|
|
Usage: "Count agents",
|
|
|
|
Flags: clientFlag.ComposeFlags(),
|
|
|
|
Action: func(ctx *cli.Context) error {
|
|
|
|
baseFlags := clientFlag.GetBaseFlags(ctx)
|
2023-03-08 19:42:40 +01:00
|
|
|
|
|
|
|
token, err := clientFlag.GetToken(baseFlags)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
client := client.New(baseFlags.ServerURL, client.WithToken(token))
|
2023-02-28 15:50:35 +01:00
|
|
|
|
|
|
|
_, total, err := client.QueryAgents(ctx.Context)
|
|
|
|
if err != nil {
|
|
|
|
return errors.WithStack(apierr.Wrap(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
hints := format.Hints{
|
|
|
|
OutputMode: baseFlags.OutputMode,
|
|
|
|
}
|
|
|
|
|
|
|
|
results := []struct {
|
|
|
|
Total int `json:"total"`
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Total: total,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := format.Write(baseFlags.Format, os.Stdout, hints, clientFlag.AsAnySlice(results)...); err != nil {
|
|
|
|
return errors.WithStack(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|