2023-02-28 15:50:35 +01:00
|
|
|
package flag
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
|
2023-03-10 11:28:37 +01:00
|
|
|
clientFlag "forge.cadoles.com/Cadoles/emissary/internal/command/api/flag"
|
2023-02-28 15:50:35 +01:00
|
|
|
"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
|
|
|
|
}
|