Skip to content

Commit

Permalink
fleetctl: Add command to show id
Browse files Browse the repository at this point in the history
Add a command that either shows the current id or transforms the given id.

Signed-off-by: Heathcliff <[email protected]>
  • Loading branch information
heathcliff26 committed Dec 23, 2024
1 parent c089010 commit 68b3dbd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
41 changes: 41 additions & 0 deletions pkg/fleetctl/appid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package fleetctl

import (
"fmt"

"github.com/heathcliff26/fleetlock/pkg/client"
systemdutils "github.com/heathcliff26/fleetlock/pkg/systemd-utils"
"github.com/spf13/cobra"
)

const flagNameMachineID = "machine-id"

// Create a new id command
func NewIDCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "id",
Short: "display this node zincati app id",
RunE: func(cmd *cobra.Command, _ []string) error {
input, err := cmd.Flags().GetString(flagNameMachineID)
if err != nil {
return err
}

var id string
if input == "" {
id, err = client.GetZincateAppID()
} else {
id, err = systemdutils.ZincatiMachineID(input)
}
if err != nil {
exitError(cmd, err)
}
fmt.Println(id)

return nil
},
}
cmd.Flags().StringP(flagNameMachineID, "i", "", "Specify the id to transform")

return cmd
}
1 change: 1 addition & 0 deletions pkg/fleetctl/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func NewRootCommand() *cobra.Command {
rootCmd.AddCommand(
NewLockCommand(),
NewReleaseCommand(),
NewIDCommand(),
version.NewCommand(Name),
)

Expand Down

0 comments on commit 68b3dbd

Please sign in to comment.