/
config.go
61 lines (49 loc) · 1.3 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
type config struct {
repo *string
version *string
status *string
description *string
provider *string
box *string
checksumType *string
checksum *string
}
func (c *config) addflags(s *flag.FlagSet) {
repo := s.String("repo", "", "path to metadata.json")
c.repo = repo
version := s.String("version", "", "version to add (SemVer)")
c.version = version
status := s.String("status", "", "status of the version")
c.status = status
description := s.String("description", "", "description of the version (markdown)")
s.StringVar(description, "desc", "", "Shortcut for --description")
c.description = description
provider := s.String("provider", "", "provider the box supports")
c.provider = provider
box := s.String("box", "", "url of the box")
c.box = box
checksumType := s.String("checksum-type", "", "type of the checksum")
c.checksumType = checksumType
checksum := s.String("checksum", "", "checksum of the box")
c.checksum = checksum
}
func usage(s *flag.FlagSet) func() {
return func() {
fmt.Fprintf(os.Stderr, "Usage: %s <command> [flags]\n", filepath.Base(os.Args[0]))
s.PrintDefaults()
}
}
func parseFlags(s *flag.FlagSet, args []string) *config {
c := &config{}
c.addflags(s)
s.Usage = usage(s)
s.Parse(args)
return c
}