-
Notifications
You must be signed in to change notification settings - Fork 32
/
main.go
97 lines (83 loc) · 2.33 KB
/
main.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
92
93
94
95
96
97
package main
import (
"fmt"
"os"
"github.com/godarch/darch/pkg/cmd/darch/commands/helpers"
"github.com/godarch/darch/pkg/cmd/darch/commands/hooks"
"github.com/godarch/darch/pkg/cmd/darch/commands/images"
"github.com/godarch/darch/pkg/cmd/darch/commands/recipes"
"github.com/godarch/darch/pkg/cmd/darch/commands/stage"
"github.com/urfave/cli"
)
// GitCommit The git commit that was compiled. This will be filled in by the compiler.
var GitCommit string
// Version The main version number that is being run at the moment.
var Version = "0.1.0"
func main() {
app := cli.NewApp()
app.Name = "darch"
app.Usage = "A tool used to build, boot and share stateless Arch images."
app.Version = Version
app.HideVersion = true
app.Commands = []cli.Command{
images.Command,
recipes.Command,
stage.Command,
helpers.Command,
hooks.Command,
{
Name: "version",
Usage: "Print version information about darch.",
Action: func(c *cli.Context) error {
fmt.Printf("version %s\n", Version)
fmt.Printf("commit %s\n", GitCommit)
return nil
},
},
}
markdownDoc := false
if len(os.Args) >= 2 {
if os.Args[1] == "markdown" {
// We are running this command to generate documentation!
os.Args = append(os.Args[:1], os.Args[2:]...)
markdownDoc = true
}
}
if markdownDoc {
for subCommandIndex, subCommand := range app.Commands {
subCommand.Action = markdownAction
app.Commands[subCommandIndex] = walkCommandsForDocumentation(subCommand)
}
}
if err := app.Run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "darch: %s\n", err)
os.Exit(1)
}
}
func markdownAction(clicontext *cli.Context) error {
fmt.Printf("**%s**\n", clicontext.Command.HelpName)
fmt.Println("")
if len(clicontext.Command.Description) > 0 {
fmt.Println("## Description")
fmt.Println("")
fmt.Println(clicontext.Command.Description)
fmt.Println("")
}
fmt.Println("## Usage")
fmt.Println("")
fmt.Printf(clicontext.Command.HelpName)
if len(clicontext.Command.ArgsUsage) > 0 {
fmt.Printf(" %s\n", clicontext.Command.ArgsUsage)
} else {
fmt.Println("")
}
fmt.Println("")
return nil
}
func walkCommandsForDocumentation(cmd cli.Command) cli.Command {
cmd.Action = markdownAction
for subCommandIndex, subCommand := range cmd.Subcommands {
cmd.Subcommands[subCommandIndex] = walkCommandsForDocumentation(subCommand)
}
return cmd
}