Skip to content

Commit

Permalink
Merge pull request #1498 from luissimas/description-flag
Browse files Browse the repository at this point in the history
Add `--description` flag to create type CLI commands
  • Loading branch information
stgraber authored Dec 17, 2024
2 parents 1492089 + b71c3ab commit d9bab5b
Show file tree
Hide file tree
Showing 39 changed files with 14,280 additions and 12,886 deletions.
8 changes: 8 additions & 0 deletions cmd/incus/cluster_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ func (c *cmdClusterGroupAssign) Run(cmd *cobra.Command, args []string) error {
type cmdClusterGroupCreate struct {
global *cmdGlobal
cluster *cmdCluster

flagDescription string
}

// Creation of a new cluster group, defining its usage, short and long descriptions, and the RunE method.
Expand All @@ -191,6 +193,8 @@ func (c *cmdClusterGroupCreate) Command() *cobra.Command {
incus cluster group create g1 < config.yaml
Create a cluster group with configuration from config.yaml`))

cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Cluster group description")+"``")

cmd.RunE = c.Run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down Expand Up @@ -245,6 +249,10 @@ func (c *cmdClusterGroupCreate) Run(cmd *cobra.Command, args []string) error {
ClusterGroupPut: stdinData,
}

if c.flagDescription != "" {
group.Description = c.flagDescription
}

err = resource.server.CreateClusterGroup(group)
if err != nil {
return err
Expand Down
11 changes: 7 additions & 4 deletions cmd/incus/config_trust.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,11 @@ type cmdConfigTrustAddCertificate struct {
config *cmdConfig
configTrust *cmdConfigTrust

flagProjects string
flagRestricted bool
flagName string
flagType string
flagProjects string
flagRestricted bool
flagName string
flagType string
flagDescription string
}

func (c *cmdConfigTrustAddCertificate) Command() *cobra.Command {
Expand All @@ -180,6 +181,7 @@ The following certificate types are supported:
cmd.Flags().StringVar(&c.flagProjects, "projects", "", i18n.G("List of projects to restrict the certificate to")+"``")
cmd.Flags().StringVar(&c.flagName, "name", "", i18n.G("Alternative certificate name")+"``")
cmd.Flags().StringVar(&c.flagType, "type", "client", i18n.G("Type of certificate")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Certificate description")+"``")

cmd.RunE = c.Run

Expand Down Expand Up @@ -246,6 +248,7 @@ func (c *cmdConfigTrustAddCertificate) Run(cmd *cobra.Command, args []string) er
cert := api.CertificatesPost{}
cert.Certificate = base64.StdEncoding.EncodeToString(x509Cert.Raw)
cert.Name = name
cert.Description = c.flagDescription

if c.flagType == "client" {
cert.Type = api.CertificateTypeClient
Expand Down
9 changes: 8 additions & 1 deletion cmd/incus/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type cmdCreate struct {
flagNoProfiles bool
flagEmpty bool
flagVM bool
flagDescription string
}

func (c *cmdCreate) Command() *cobra.Command {
Expand Down Expand Up @@ -63,6 +64,7 @@ incus launch images:debian/12 v2 --vm -d root,size=50GiB -d root,io.bus=nvme
cmd.Flags().BoolVar(&c.flagNoProfiles, "no-profiles", false, i18n.G("Create the instance with no profiles applied"))
cmd.Flags().BoolVar(&c.flagEmpty, "empty", false, i18n.G("Create an empty instance"))
cmd.Flags().BoolVar(&c.flagVM, "vm", false, i18n.G("Create a virtual machine"))
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Instance description")+"``")

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
Expand Down Expand Up @@ -283,7 +285,12 @@ func (c *cmdCreate) create(conf *config.Config, args []string, launch bool) (inc

req.Config = configMap
req.Ephemeral = c.flagEphemeral
req.Description = stdinData.Description

if c.flagDescription != "" {
req.Description = c.flagDescription
} else {
req.Description = stdinData.Description
}

if !c.flagNoProfiles && len(profiles) == 0 {
if len(stdinData.Profiles) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions cmd/incus/image_alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type cmdImageAliasCreate struct {
global *cmdGlobal
image *cmdImage
imageAlias *cmdImageAlias

flagDescription string
}

func (c *cmdImageAliasCreate) Command() *cobra.Command {
Expand All @@ -66,6 +68,8 @@ func (c *cmdImageAliasCreate) Command() *cobra.Command {
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`Create aliases for existing images`))

cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Image alias description")+"``")

cmd.RunE = c.Run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down Expand Up @@ -111,6 +115,7 @@ func (c *cmdImageAliasCreate) Run(cmd *cobra.Command, args []string) error {
alias := api.ImageAliasesPost{}
alias.Name = resource.name
alias.Target = args[1]
alias.Description = c.flagDescription

return resource.server.CreateImageAlias(alias)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/incus/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ func (c *cmdInfo) instanceInfo(d incus.InstanceServer, remote config.Remote, nam
}

fmt.Printf(i18n.G("Name: %s")+"\n", inst.Name)

fmt.Printf(i18n.G("Description: %s")+"\n", inst.Description)
fmt.Printf(i18n.G("Status: %s")+"\n", strings.ToUpper(inst.Status))

instType := inst.Type
Expand Down
7 changes: 7 additions & 0 deletions cmd/incus/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ func (c *cmdNetworkAttachProfile) Run(cmd *cobra.Command, args []string) error {
type cmdNetworkCreate struct {
global *cmdGlobal
network *cmdNetwork

flagDescription string
}

func (c *cmdNetworkCreate) Command() *cobra.Command {
Expand All @@ -346,6 +348,7 @@ incus network create bar network=baz --type ovn

cmd.Flags().StringVar(&c.network.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVarP(&c.network.flagType, "type", "t", "", i18n.G("Network type")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Network description")+"``")

cmd.RunE = c.Run

Expand Down Expand Up @@ -399,6 +402,10 @@ func (c *cmdNetworkCreate) Run(cmd *cobra.Command, args []string) error {
network.Name = resource.name
network.Type = c.network.flagType

if c.flagDescription != "" {
network.Description = c.flagDescription
}

if network.Config == nil {
network.Config = map[string]string{}
}
Expand Down
16 changes: 16 additions & 0 deletions cmd/incus/network_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,8 @@ func (c *cmdNetworkACLGet) Run(cmd *cobra.Command, args []string) error {
type cmdNetworkACLCreate struct {
global *cmdGlobal
networkACL *cmdNetworkACL

flagDescription string
}

func (c *cmdNetworkACLCreate) Command() *cobra.Command {
Expand All @@ -383,6 +385,8 @@ func (c *cmdNetworkACLCreate) Command() *cobra.Command {
incus network acl create a1 < config.yaml
Create network acl with configuration from config.yaml`))

cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Network ACL description")+"``")

cmd.RunE = c.Run

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down Expand Up @@ -437,6 +441,10 @@ func (c *cmdNetworkACLCreate) Run(cmd *cobra.Command, args []string) error {
NetworkACLPut: aclPut,
}

if c.flagDescription != "" {
acl.Description = c.flagDescription
}

if acl.Config == nil {
acl.Config = map[string]string{}
}
Expand Down Expand Up @@ -852,6 +860,7 @@ type cmdNetworkACLRule struct {
global *cmdGlobal
networkACL *cmdNetworkACL
flagRemoveForce bool
flagDescription string
}

func (c *cmdNetworkACLRule) Command() *cobra.Command {
Expand All @@ -874,6 +883,9 @@ func (c *cmdNetworkACLRule) CommandAdd() *cobra.Command {
cmd.Use = usage("add", i18n.G("[<remote>:]<ACL> <direction> <key>=<value>..."))
cmd.Short = i18n.G("Add rules to an ACL")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G("Add rules to an ACL"))

cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Rule description")+"``")

cmd.RunE = c.RunAdd

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
Expand Down Expand Up @@ -987,6 +999,10 @@ func (c *cmdNetworkACLRule) RunAdd(cmd *cobra.Command, args []string) error {
return err
}

if c.flagDescription != "" {
rule.Description = c.flagDescription
}

rule.Normalise() // Strip space.

// Default to enabled if not specified.
Expand Down
10 changes: 10 additions & 0 deletions cmd/incus/network_forward.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ func (c *cmdNetworkForwardShow) Run(cmd *cobra.Command, args []string) error {
type cmdNetworkForwardCreate struct {
global *cmdGlobal
networkForward *cmdNetworkForward

flagDescription string
}

func (c *cmdNetworkForwardCreate) Command() *cobra.Command {
Expand All @@ -330,6 +332,7 @@ incus network forward create n1 127.0.0.1 < config.yaml
cmd.RunE = c.Run

cmd.Flags().StringVar(&c.networkForward.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Network forward description")+"``")

return cmd
}
Expand Down Expand Up @@ -391,6 +394,10 @@ func (c *cmdNetworkForwardCreate) Run(cmd *cobra.Command, args []string) error {
NetworkForwardPut: forwardPut,
}

if c.flagDescription != "" {
forward.Description = c.flagDescription
}

forward.Normalise()

client := resource.server
Expand Down Expand Up @@ -888,6 +895,7 @@ type cmdNetworkForwardPort struct {
global *cmdGlobal
networkForward *cmdNetworkForward
flagRemoveForce bool
flagDescription string
}

func (c *cmdNetworkForwardPort) Command() *cobra.Command {
Expand All @@ -913,6 +921,7 @@ func (c *cmdNetworkForwardPort) CommandAdd() *cobra.Command {
cmd.RunE = c.RunAdd

cmd.Flags().StringVar(&c.networkForward.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Port description")+"``")

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
Expand Down Expand Up @@ -973,6 +982,7 @@ func (c *cmdNetworkForwardPort) RunAdd(cmd *cobra.Command, args []string) error
Protocol: args[2],
ListenPort: args[3],
TargetAddress: args[4],
Description: c.flagDescription,
}

if len(args) > 5 {
Expand Down
12 changes: 12 additions & 0 deletions cmd/incus/network_load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ func (c *cmdNetworkLoadBalancerShow) Run(cmd *cobra.Command, args []string) erro
type cmdNetworkLoadBalancerCreate struct {
global *cmdGlobal
networkLoadBalancer *cmdNetworkLoadBalancer
flagDescription string
}

func (c *cmdNetworkLoadBalancerCreate) Command() *cobra.Command {
Expand All @@ -334,6 +335,7 @@ incus network load-balancer create n1 127.0.0.1 < config.yaml
cmd.RunE = c.Run

cmd.Flags().StringVar(&c.networkLoadBalancer.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Load balancer description")+"``")

return cmd
}
Expand Down Expand Up @@ -395,6 +397,10 @@ func (c *cmdNetworkLoadBalancerCreate) Run(cmd *cobra.Command, args []string) er
NetworkLoadBalancerPut: loadBalancerPut,
}

if c.flagDescription != "" {
loadBalancer.Description = c.flagDescription
}

loadBalancer.Normalise()

client := resource.server
Expand Down Expand Up @@ -868,6 +874,7 @@ func (c *cmdNetworkLoadBalancerDelete) Run(cmd *cobra.Command, args []string) er
type cmdNetworkLoadBalancerBackend struct {
global *cmdGlobal
networkLoadBalancer *cmdNetworkLoadBalancer
flagDescription string
}

func (c *cmdNetworkLoadBalancerBackend) Command() *cobra.Command {
Expand All @@ -893,6 +900,7 @@ func (c *cmdNetworkLoadBalancerBackend) CommandAdd() *cobra.Command {
cmd.RunE = c.RunAdd

cmd.Flags().StringVar(&c.networkLoadBalancer.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Backend description")+"``")

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
Expand Down Expand Up @@ -948,6 +956,7 @@ func (c *cmdNetworkLoadBalancerBackend) RunAdd(cmd *cobra.Command, args []string
backend := api.NetworkLoadBalancerBackend{
Name: args[2],
TargetAddress: args[3],
Description: c.flagDescription,
}

if len(args) >= 5 {
Expand Down Expand Up @@ -1057,6 +1066,7 @@ type cmdNetworkLoadBalancerPort struct {
global *cmdGlobal
networkLoadBalancer *cmdNetworkLoadBalancer
flagRemoveForce bool
flagDescription string
}

func (c *cmdNetworkLoadBalancerPort) Command() *cobra.Command {
Expand All @@ -1082,6 +1092,7 @@ func (c *cmdNetworkLoadBalancerPort) CommandAdd() *cobra.Command {
cmd.RunE = c.RunAdd

cmd.Flags().StringVar(&c.networkLoadBalancer.flagTarget, "target", "", i18n.G("Cluster member name")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Port description")+"``")

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
Expand Down Expand Up @@ -1138,6 +1149,7 @@ func (c *cmdNetworkLoadBalancerPort) RunAdd(cmd *cobra.Command, args []string) e
Protocol: args[2],
ListenPort: args[3],
TargetBackend: util.SplitNTrimSpace(args[4], ",", -1, false),
Description: c.flagDescription,
}

loadBalancer.Ports = append(loadBalancer.Ports, port)
Expand Down
8 changes: 7 additions & 1 deletion cmd/incus/network_peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ type cmdNetworkPeerCreate struct {
global *cmdGlobal
networkPeer *cmdNetworkPeer

flagType string
flagType string
flagDescription string
}

func (c *cmdNetworkPeerCreate) Command() *cobra.Command {
Expand All @@ -331,6 +332,7 @@ incus network peer create default peer3 web/default < config.yaml
cmd.RunE = c.Run

cmd.Flags().StringVar(&c.flagType, "type", "local", i18n.G("Type of peer (local or remote)")+"``")
cmd.Flags().StringVar(&c.flagDescription, "description", "", i18n.G("Peer description")+"``")

cmd.ValidArgsFunction = func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) == 0 {
Expand Down Expand Up @@ -426,6 +428,10 @@ func (c *cmdNetworkPeerCreate) Run(cmd *cobra.Command, args []string) error {
peer.TargetIntegration = target
}

if c.flagDescription != "" {
peer.Description = c.flagDescription
}

client := resource.server

err = client.CreateNetworkPeer(resource.name, peer)
Expand Down
Loading

0 comments on commit d9bab5b

Please sign in to comment.