-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a command that either shows the current id or transforms the given id. Signed-off-by: Heathcliff <[email protected]>
- Loading branch information
1 parent
c089010
commit 68b3dbd
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters