feature/move-command (#18)

Co-authored-by: kjuulh <contact@kjuulh.io>
Reviewed-on: https://git.front.kjuulh.io/kjuulh/octopush/pulls/18
This commit is contained in:
2022-09-21 21:53:49 +02:00
parent 8e12bf1bff
commit 571b5811de
21 changed files with 499 additions and 408 deletions

View File

@@ -1,14 +0,0 @@
package commands
import "github.com/spf13/cobra"
func CreateOctopushCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "octopush",
// Run: func(cmd *cobra.Command, args []string) { },
}
cmd.AddCommand(CreateOctopushProcessCmd())
return cmd
}

View File

@@ -1,18 +0,0 @@
package main
import (
"os"
"git.front.kjuulh.io/kjuulh/octopush/cmd/octopush/commands"
)
func main() {
Execute()
}
func Execute() {
err := commands.CreateOctopushCmd().Execute()
if err != nil {
os.Exit(1)
}
}

View File

@@ -0,0 +1,51 @@
package commands
import (
"git.front.kjuulh.io/kjuulh/octopush/internal/cli"
"git.front.kjuulh.io/kjuulh/octopush/internal/commands"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func CreateOctopushProcessCmd(logger *zap.Logger) *cobra.Command {
var (
actionsRepo string
branch string
path string
)
cmd := &cobra.Command{
Use: "process",
RunE: func(cmd *cobra.Command, args []string) error {
if err := cmd.ParseFlags(args); err != nil {
return err
}
ctx := cmd.Context()
deps, err := cli.Start(ctx, logger)
if err != nil {
return err
}
err = commands.
NewProcessRepos(logger, deps).
Process(ctx, actionsRepo, branch, path)
if err != nil {
return err
}
return nil
},
}
pf := cmd.PersistentFlags()
pf.StringVar(&actionsRepo, "actions-repo", "", "actions repo is the location of your actions, not where to apply the actions themselves, that should be self contained")
cmd.MarkPersistentFlagRequired("actions-repo")
pf.StringVar(&branch, "branch", "main", "which branch to look for actions in, will default to main")
pf.StringVar(&path, "path", "", "the location of the path inside the repository")
cmd.MarkPersistentFlagRequired("path")
return cmd
}

View File

@@ -0,0 +1,18 @@
package commands
import (
"git.front.kjuulh.io/kjuulh/octopush/cmd/octopush/commands/server"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func CreateOctopushCmd(logger *zap.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "octopush",
}
cmd.AddCommand(CreateOctopushProcessCmd(logger))
cmd.AddCommand(server.CreateOctopushServerCmd(logger))
return cmd
}

View File

@@ -1,4 +1,4 @@
package commands
package server
import (
"bytes"

View File

@@ -0,0 +1,16 @@
package server
import (
"github.com/spf13/cobra"
"go.uber.org/zap"
)
func CreateOctopushServerCmd(logger *zap.Logger) *cobra.Command {
cmd := &cobra.Command{
Use: "server",
}
cmd.AddCommand(CreateOctopushProcessCmd())
return cmd
}

28
cmd/octopush/octopush.go Normal file
View File

@@ -0,0 +1,28 @@
package main
import (
"os"
"git.front.kjuulh.io/kjuulh/octopush/cmd/octopush/commands"
"git.front.kjuulh.io/kjuulh/octopush/internal/logger"
"go.uber.org/zap"
)
func main() {
logger, err := logger.New()
if err != nil {
panic(err)
}
_ = logger.Sync()
zap.ReplaceGlobals(logger)
Execute(logger)
}
func Execute(logger *zap.Logger) {
err := commands.CreateOctopushCmd(logger).Execute()
if err != nil {
os.Exit(1)
}
}