Browse Source

En cours de développement

master
mls-361 9 months ago
parent
commit
7d8e970898
  1. 14
      cmd/main.go
  2. 12
      internal/cli/cli.go
  3. 6
      internal/cli/jobs.go

14
cmd/main.go

@ -40,7 +40,7 @@ func init() {
rand.Seed(time.Now().UnixNano())
}
func buildComponents(ccs *components.Components) error {
func buildComponents(args []string, ccs *components.Components) error {
var err error
ccs.Config, err = config.Load(ccs)
@ -68,7 +68,7 @@ func buildComponents(ccs *components.Components) error {
return errors.WithMessage(err, "model") ////////////////////////////////////////////////////////////////////////
}
if len(os.Args) > 1 {
if len(args) != 0 {
return nil
}
@ -112,7 +112,7 @@ func waitEnd(server components.Server) (*sync.WaitGroup, chan struct{}) {
return group, endCh
}
func run() error {
func run(args []string) error {
app := application.New("armen", _version, _builtAt)
if err := app.Initialize(); err != nil {
return app.OnError(err)
@ -122,7 +122,7 @@ func run() error {
defer ccs.Shutdown()
if err := buildComponents(ccs); err != nil {
if err := buildComponents(args, ccs); err != nil {
if ccs.Logger != nil {
ccs.Logger.Fatal( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
"Components build error",
@ -133,8 +133,8 @@ func run() error {
return app.OnError(err)
}
if len(os.Args) > 1 {
return app.OnError(cli.Run(ccs, os.Args[1:]))
if len(args) != 0 {
return app.OnError(cli.Run(args, ccs))
}
group, endCh := waitEnd(ccs.Server)
@ -153,7 +153,7 @@ func run() error {
}
func main() {
if run() != nil {
if run(os.Args[1:]) != nil {
os.Exit(1)
}
}

12
internal/cli/cli.go

@ -26,7 +26,7 @@ func newFlagSet(ccs *components.Components) *flag.FlagSet {
return fs
}
func decrypt(ccs *components.Components, args []string) error {
func decrypt(args []string, ccs *components.Components) error {
if len(args) != 1 {
help()
return _errArgs
@ -42,7 +42,7 @@ func decrypt(ccs *components.Components, args []string) error {
return nil
}
func encrypt(ccs *components.Components, args []string) error {
func encrypt(args []string, ccs *components.Components) error {
if len(args) != 1 {
help()
return _errArgs
@ -96,14 +96,14 @@ The commands are:
`)
}
func Run(ccs *components.Components, args []string) error {
func Run(args []string, ccs *components.Components) error {
switch args[0] {
case "decrypt":
return decrypt(ccs, args[1:])
return decrypt(args[1:], ccs)
case "encrypt":
return encrypt(ccs, args[1:])
return encrypt(args[1:], ccs)
case "jobs":
return jobs(ccs, args[1:])
return jobs(args[1:], ccs)
case "version":
version(ccs)
default:

6
internal/cli/jobs.go

@ -44,7 +44,7 @@ func setCategory(job *jw.Job, value string) error {
return nil
}
func jobCreate(ccs *components.Components, args []string) error {
func jobCreate(args []string, ccs *components.Components) error {
if len(args) < 2 {
help()
return _errArgs
@ -88,7 +88,7 @@ func jobCreate(ccs *components.Components, args []string) error {
return nil
}
func jobs(ccs *components.Components, args []string) error {
func jobs(args []string, ccs *components.Components) error {
if len(args) < 1 {
help()
return _errArgs
@ -96,7 +96,7 @@ func jobs(ccs *components.Components, args []string) error {
switch args[0] {
case "create":
return jobCreate(ccs, args[1:])
return jobCreate(args[1:], ccs)
default:
help()
}

Loading…
Cancel
Save