mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-26 11:03:34 +00:00
--------- Co-authored-by: Pasha Sviderski <me@psviderski.name> Co-authored-by: Anton Ovchinnikov <anton@tonyo.info>
40 lines
916 B
Go
40 lines
916 B
Go
package machine
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/psviderski/uncloud/internal/daemon"
|
|
"github.com/psviderski/uncloud/internal/machine"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
type tokenOptions struct {
|
|
dataDir string
|
|
}
|
|
|
|
func NewTokenCommand() *cobra.Command {
|
|
opts := tokenOptions{}
|
|
cmd := &cobra.Command{
|
|
Use: "token",
|
|
Short: "Print the local machine's token for adding it to a cluster.",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
token, err := daemon.MachineToken(opts.dataDir)
|
|
if err != nil {
|
|
return fmt.Errorf("get machine token: %w", err)
|
|
}
|
|
tokenStr, err := token.String()
|
|
if err != nil {
|
|
return fmt.Errorf("encode machine token: %w", err)
|
|
}
|
|
fmt.Println(tokenStr)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVarP(&opts.dataDir, "data-dir", "d", machine.DefaultDataDir,
|
|
"Directory for storing persistent machine state.")
|
|
_ = cmd.MarkFlagDirname("data-dir")
|
|
|
|
return cmd
|
|
}
|