-
Notifications
You must be signed in to change notification settings - Fork 31
/
cli_view_handler.go
57 lines (50 loc) · 1.57 KB
/
cli_view_handler.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
package main
import (
"fmt"
"strings"
"github.com/urfave/cli"
)
// View holds the data for the various types of files that can
// be bootstrapped
type View struct {
Filename string
Data string
}
// ViewMap holds the data for the application to use to display
// the file
var ViewMap = map[string]*View{
"dockerfile": &View{"Dockerfile", DataDockerfile},
"makefile": &View{"Makefile", DataMakefile},
".dockerignore": &View{".dockerignore", DataDotDockerignore},
".gitignore": &View{".gitignore", DataDotGitignore},
"main.go": &View{"main.go", DataMainDotgo},
"go.mod": &View{"go.mod", DataGoDotMod},
}
func getViewCommand(config *Config, logger *Logger) cli.Command {
description := "checkout files seeded with the init sub-command where the [filename] argument is one of:"
for filename := range ViewMap {
description = fmt.Sprintf("%s\n - %s", description, filename)
}
return cli.Command{
Action: getViewAction(config, logger),
Aliases: []string{"V"},
ArgsUsage: "[filename]",
Description: description,
Name: "view",
Usage: "checkout files seeded with the init sub-command",
}
}
func getViewAction(config *Config, logger *Logger) cli.ActionFunc {
return func(c *cli.Context) error {
config.RunView = true
config.View = c.Args().First()
fileKey := strings.ToLower(config.View)
config.assignDefaults()
config.interpretLogLevel()
if ViewMap[fileKey] != nil {
logger.Info(ViewMap[fileKey].Data)
return nil
}
return fmt.Errorf("the requested file, '%s', does not seem to exist", config.View)
}
}