/
config.go
91 lines (82 loc) · 2.33 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package command
import (
"errors"
"github.com/ysugimoto/go-args"
"github.com/ysugimoto/ginger/config"
"github.com/ysugimoto/ginger/logger"
)
// Config is a struct for update project configuration.
type Config struct {
Command
log *logger.Logger
}
func NewConfig() *Config {
return &Config{
log: logger.WithNamespace("ginger.config"),
}
}
// Show this command help.
func (c *Config) Help() string {
return commandHeader() + `
config - Set or update project confiugration.
Usage:
$ ginger config [options]
Options:
--profile : Using profile name
--region : Set project region
--role : Set default lambda execution role
--bucket : Set S3 bucket name which you want to use
--hook : Register deploy hook command
`
}
// Run the config command.
//
// >>> doc
//
// ## Update configuration
//
// Update configurations by supplied command options.
//
// ```
// $ ginger config [options]
// ```
//
// | option | description |
// |:---------:|:-----------------------------------------------------------------------------|
// | --profile | Accout profile name. If empty, ginger uses `default` or environment variable |
// | --region | Region name to deploy |
// | --bucket | S3 bucket name |
// | --hook | Deploy hook command |
//
// <<< doc
func (c *Config) Run(ctx *args.Context) error {
conf := config.Load()
if !conf.Exists() {
c.log.Error("Configuration file could not load. Run `ginger init` before.")
return errors.New("")
}
defer conf.Write()
var v string
if v = ctx.String("profile"); v != "" {
conf.Profile = v
c.log.Printf("Set use profile as \"%s\"\n", v)
}
if v = ctx.String("region"); v != "" {
conf.Region = v
c.log.Printf("Set AWS region as \"%s\"\n", v)
}
if v = ctx.String("role"); v != "" {
conf.DefaultLambdaRole = v
c.log.Printf("Set Lambda execution role as \"%s\"\n", v)
}
if v = ctx.String("bucket"); v != "" {
conf.S3BucketName = v
c.log.Printf("Set S3 bucket name as \"%s\"\n", v)
}
if v = ctx.String("hook"); v != "" {
conf.DeployHookCommand = v
c.log.Print("Set deploy hook command.")
}
c.log.Info("Configuration updated!")
return nil
}