feat(cli): add register command basic functions
This commit is contained in:
parent
88ae188699
commit
561bfad7c5
|
@ -14,7 +14,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
const version = "0.1"
|
const version = "0.1.5"
|
||||||
|
|
||||||
// initLogging setup the global logrus logger.
|
// initLogging setup the global logrus logger.
|
||||||
func initLogging(cfg config.Config) {
|
func initLogging(cfg config.Config) {
|
||||||
|
@ -37,10 +37,10 @@ func Execute(ctx context.Context) {
|
||||||
|
|
||||||
// ./act_runner
|
// ./act_runner
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: "act [event name to run]\nIf no event name passed, will default to \"on: push\"",
|
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.",
|
Short: "Run GitHub actions locally by specifying the event name (e.g. `push`) or an action name directly.",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: runRoot(ctx, task),
|
// RunE: runRoot(ctx, task),
|
||||||
Version: version,
|
Version: version,
|
||||||
SilenceUsage: true,
|
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.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.")
|
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
|
// ./act_runner daemon
|
||||||
daemonCmd := &cobra.Command{
|
daemonCmd := &cobra.Command{
|
||||||
Aliases: []string{"daemon"},
|
Use: "daemon",
|
||||||
Use: "execute runner daemon",
|
Short: "Run as a runner daemon",
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: runDaemon(ctx, task.Input.EnvFile),
|
RunE: runDaemon(ctx, task.Input.EnvFile),
|
||||||
}
|
}
|
||||||
// add all command
|
// add all command
|
||||||
rootCmd.AddCommand(daemonCmd)
|
rootCmd.AddCommand(daemonCmd)
|
||||||
|
|
||||||
|
// hide completion command
|
||||||
|
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||||
|
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
|
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue