From 561bfad7c5413e29f61f44fc4526ad6123705c4c Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Tue, 15 Nov 2022 20:46:29 +0800 Subject: [PATCH] feat(cli): add register command basic functions --- cmd/{root.go => cmd.go} | 34 +++++++++++++++++++++++++--------- cmd/register.go | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+), 9 deletions(-) rename cmd/{root.go => cmd.go} (62%) create mode 100644 cmd/register.go diff --git a/cmd/root.go b/cmd/cmd.go similarity index 62% rename from cmd/root.go rename to cmd/cmd.go index 750e1b1..cf12a46 100644 --- a/cmd/root.go +++ b/cmd/cmd.go @@ -14,7 +14,7 @@ import ( "github.com/spf13/cobra" ) -const version = "0.1" +const version = "0.1.5" // initLogging setup the global logrus logger. func initLogging(cfg config.Config) { @@ -37,10 +37,10 @@ func Execute(ctx context.Context) { // ./act_runner rootCmd := &cobra.Command{ - Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"", - Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", - Args: cobra.MaximumNArgs(1), - RunE: runRoot(ctx, task), + Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"", + Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.", + Args: cobra.MaximumNArgs(1), + // RunE: runRoot(ctx, task), Version: version, SilenceUsage: true, } @@ -49,16 +49,32 @@ func Execute(ctx context.Context) { rootCmd.PersistentFlags().StringVarP(&task.Input.ForgeInstance, "forge-instance", "", "github.com", "Forge instance to use.") rootCmd.PersistentFlags().StringVarP(&task.Input.EnvFile, "env-file", "", ".env", "Read in a file of environment variables.") + // ./act_runner register + var regArgs registerArgs + registerCmd := &cobra.Command{ + Use: "register", + Short: "Register a runner to the server", + Args: cobra.MaximumNArgs(0), + RunE: runRegister(ctx, ®Args), // must use a pointer to regArgs + } + registerCmd.Flags().BoolVarP(®Args.NoInteractive, "no-interactive", "", false, "Disable interactive mode") + registerCmd.Flags().StringVarP(®Args.InstanceAddr, "instance", "", "", "Gitea instance address") + registerCmd.Flags().StringVarP(®Args.Token, "token", "", "", "Runner token") + rootCmd.AddCommand(registerCmd) + // ./act_runner daemon daemonCmd := &cobra.Command{ - Aliases: []string{"daemon"}, - Use: "execute runner daemon", - Args: cobra.MaximumNArgs(1), - RunE: runDaemon(ctx, task.Input.EnvFile), + Use: "daemon", + Short: "Run as a runner daemon", + Args: cobra.MaximumNArgs(1), + RunE: runDaemon(ctx, task.Input.EnvFile), } // add all command rootCmd.AddCommand(daemonCmd) + // hide completion command + rootCmd.CompletionOptions.HiddenDefaultCmd = true + if err := rootCmd.Execute(); err != nil { os.Exit(1) } diff --git a/cmd/register.go b/cmd/register.go new file mode 100644 index 0000000..fe54c26 --- /dev/null +++ b/cmd/register.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "context" + + log "github.com/sirupsen/logrus" + "github.com/spf13/cobra" +) + +// runRegister registers a runner to the server +func runRegister(ctx context.Context, regArgs *registerArgs) func(*cobra.Command, []string) error { + return func(cmd *cobra.Command, args []string) error { + log.Infoln("Starting register to gitea instance") + return nil + } +} + +// registerArgs represents the arguments for register command +type registerArgs struct { + NoInteractive bool + InstanceAddr string + Token string +}