| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. | 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package application | 5 package application |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "github.com/maruel/subcommands" | 8 "github.com/maruel/subcommands" |
| 9 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
| 10 | 10 |
| 11 "github.com/luci/luci-go/common/cli" | 11 "github.com/luci/luci-go/common/cli" |
| 12 "github.com/luci/luci-go/common/errors" | 12 "github.com/luci/luci-go/common/errors" |
| 13 "github.com/luci/luci-go/common/logging" | 13 "github.com/luci/luci-go/common/logging" |
| 14 | 14 |
| 15 "github.com/luci/luci-go/vpython/venv" | 15 "github.com/luci/luci-go/vpython/venv" |
| 16 ) | 16 ) |
| 17 | 17 |
| 18 var subcommandInstall = &subcommands.Command{ | 18 var subcommandInstall = &subcommands.Command{ |
| 19 UsageLine: "install", | 19 UsageLine: "install", |
| 20 ShortDesc: "installs the configured VirtualEnv", | 20 ShortDesc: "installs the configured VirtualEnv", |
| 21 LongDesc: "installs the configured VirtualEnv, but doesn't run any asso
ciated commands", | 21 LongDesc: "installs the configured VirtualEnv, but doesn't run any asso
ciated commands", |
| 22 Advanced: false, | 22 Advanced: false, |
| 23 CommandRun: func() subcommands.CommandRun { | 23 CommandRun: func() subcommands.CommandRun { |
| 24 » » return &installCommandRun{} | 24 » » var cr installCommandRun |
| 25 |
| 26 » » fs := cr.GetFlags() |
| 27 » » fs.StringVar(&cr.name, "name", cr.name, |
| 28 » » » "Use this VirtualEnv name, instead of generating one via
hash. This will force specification "+ |
| 29 » » » » "validation, causing any existing VirtualEnv wit
h this name to be deleted and reprovisioned "+ |
| 30 » » » » "if it doesn't match.") |
| 31 |
| 32 » » return &cr |
| 25 }, | 33 }, |
| 26 } | 34 } |
| 27 | 35 |
| 28 type installCommandRun struct { | 36 type installCommandRun struct { |
| 29 subcommands.CommandRunBase | 37 subcommands.CommandRunBase |
| 38 |
| 39 name string |
| 30 } | 40 } |
| 31 | 41 |
| 32 func (cr *installCommandRun) Run(app subcommands.Application, args []string, env
subcommands.Env) int { | 42 func (cr *installCommandRun) Run(app subcommands.Application, args []string, env
subcommands.Env) int { |
| 33 c := cli.GetContext(app, cr, env) | 43 c := cli.GetContext(app, cr, env) |
| 34 a := getApplication(c, args) | 44 a := getApplication(c, args) |
| 45 a.opts.EnvConfig.PruneThreshold = 0 // Don't prune on install. |
| 46 a.opts.EnvConfig.OverrideName = cr.name |
| 35 | 47 |
| 36 return run(c, func(c context.Context) error { | 48 return run(c, func(c context.Context) error { |
| 37 err := venv.With(c, a.opts.EnvConfig, false, func(context.Contex
t, *venv.Env) error { | 49 err := venv.With(c, a.opts.EnvConfig, false, func(context.Contex
t, *venv.Env) error { |
| 38 return nil | 50 return nil |
| 39 }) | 51 }) |
| 40 if err != nil { | 52 if err != nil { |
| 41 return errors.Annotate(err).Reason("failed to setup the
environment").Err() | 53 return errors.Annotate(err).Reason("failed to setup the
environment").Err() |
| 42 } | 54 } |
| 43 | 55 |
| 44 logging.Infof(c, "Successfully setup the environment.") | 56 logging.Infof(c, "Successfully setup the environment.") |
| 45 return nil | 57 return nil |
| 46 }) | 58 }) |
| 47 } | 59 } |
| OLD | NEW |