Skip to content

Commit

Permalink
move batch command into install.go
Browse files Browse the repository at this point in the history
  • Loading branch information
mrosset committed Feb 24, 2019
1 parent ce18edf commit 63f4720
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
36 changes: 36 additions & 0 deletions install.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,42 @@ var (
}
)

func batch(ctx *cli.Context) error {
var errors []error
if ctx.Bool("s") {
return install(ctx)
}
if !ctx.Args().Present() {
return fmt.Errorf("install requires a 'PLAN' argument. see: 'via help install'")
}

config.Root = via.Path(ctx.String("r"))

batch := via.NewBatch(config)
for _, a := range ctx.Args().Slice() {
p, err := via.NewPlan(config, a)
if err != nil {
return err
}
if p.Cid == "" {
return fmt.Errorf("plan '%s' does not have a Cid. Has the plan been built?", p.Name)
}
if err := batch.Walk(p); err != nil {
return err
}
}
switch ctx.Bool("y") {
case false:
errors = batch.PromptInstall()
case true:
errors = batch.Install()
}
if len(errors) > 0 {
return errors[0]
}
return nil
}

// FIXME: this function is deprecated and should be replaced with batch
func install(ctx *cli.Context) error {
config.Root = via.Path(ctx.String("r"))
Expand Down
38 changes: 0 additions & 38 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,44 +320,6 @@ func daemon(_ *cli.Context) error {
return via.StartDaemon(config)
}

// TODO: move this to install.go
func batch(ctx *cli.Context) error {
var errors []error
if ctx.Bool("s") {
return install(ctx)
}
if !ctx.Args().Present() {
return fmt.Errorf("install requires a 'PLAN' argument. see: 'via help install'")
}

config.Root = via.Path(ctx.String("r"))

batch := via.NewBatch(config)
for _, a := range ctx.Args().Slice() {
p, err := via.NewPlan(config, a)
if err != nil {
return err
}
if p.Cid == "" {
return fmt.Errorf("plan '%s' does not have a Cid. Has the plan been built?", p.Name)
}
if err := batch.Walk(p); err != nil {
return err
}
}
switch ctx.Bool("y") {
case false:
errors = batch.PromptInstall()
case true:
errors = batch.Install()

}
if len(errors) > 0 {
log.Fatal(errors)
}
return nil
}

func remove(ctx *cli.Context) error {
for _, arg := range ctx.Args().Slice() {
if err := via.Remove(config, arg); err != nil {
Expand Down
1 change: 1 addition & 0 deletions org/TODOs.org
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ functions produces side effects.
** DONE use Path as function arguments and return Path arguments
** DONE use Path in main
** DONE use dedicated functions for Action literals
** TODO end user docker instance
** TODO install build depends in namespace, clean namespace after
** TODO implement postinstall
** TODO Expand Config using UnMarshal and Marshal?
Expand Down

0 comments on commit 63f4720

Please sign in to comment.