feat(cli): add register command basic functions

This commit is contained in:
fuxiaohei 2022-11-15 20:46:29 +08:00 committed by Jason Song
parent 88ae188699
commit 561bfad7c5
2 changed files with 48 additions and 9 deletions

View File

@ -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, &regArgs), // must use a pointer to regArgs
}
registerCmd.Flags().BoolVarP(&regArgs.NoInteractive, "no-interactive", "", false, "Disable interactive mode")
registerCmd.Flags().StringVarP(&regArgs.InstanceAddr, "instance", "", "", "Gitea instance address")
registerCmd.Flags().StringVarP(&regArgs.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)
}

23
cmd/register.go Normal file
View File

@ -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
}