emissary/internal/command/client/agent/flag/flag.go

35 lines
719 B
Go
Raw Permalink Normal View History

package flag
import (
"errors"
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/client/flag"
"forge.cadoles.com/Cadoles/emissary/internal/datastore"
"github.com/urfave/cli/v2"
)
func WithAgentFlags(flags ...cli.Flag) []cli.Flag {
baseFlags := clientFlag.ComposeFlags(
&cli.Int64Flag{
Name: "agent-id",
Aliases: []string{"a"},
Usage: "use `AGENT_ID` as selected agent",
Value: -1,
},
)
flags = append(flags, baseFlags...)
return flags
}
func AssertAgentID(ctx *cli.Context) (datastore.AgentID, error) {
rawAgentID := ctx.Int64("agent-id")
if rawAgentID == -1 {
return -1, errors.New("flag 'agent-id' is required")
}
return datastore.AgentID(rawAgentID), nil
}