-
Notifications
You must be signed in to change notification settings - Fork 0
/
utility.go
112 lines (93 loc) · 3.79 KB
/
utility.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package utility
// Copyright (c) 2018 Bhojpur Consulting Private Limited, India. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import (
"github.com/bhojpur/web/cmd/utility/commands"
_ "github.com/bhojpur/web/cmd/utility/commands/api"
_ "github.com/bhojpur/web/cmd/utility/commands/bale"
_ "github.com/bhojpur/web/cmd/utility/commands/codegen"
_ "github.com/bhojpur/web/cmd/utility/commands/dev"
_ "github.com/bhojpur/web/cmd/utility/commands/dlv"
_ "github.com/bhojpur/web/cmd/utility/commands/dockerize"
_ "github.com/bhojpur/web/cmd/utility/commands/generate"
_ "github.com/bhojpur/web/cmd/utility/commands/hprose"
_ "github.com/bhojpur/web/cmd/utility/commands/migrate"
_ "github.com/bhojpur/web/cmd/utility/commands/new"
_ "github.com/bhojpur/web/cmd/utility/commands/pack"
_ "github.com/bhojpur/web/cmd/utility/commands/rs"
_ "github.com/bhojpur/web/cmd/utility/commands/run"
_ "github.com/bhojpur/web/cmd/utility/commands/server"
_ "github.com/bhojpur/web/cmd/utility/commands/update"
_ "github.com/bhojpur/web/cmd/utility/commands/version"
"github.com/bhojpur/web/pkg/client/utils"
)
func IfGenerateDocs(name string, args []string) bool {
if name != "generate" {
return false
}
for _, a := range args {
if a == "docs" {
return true
}
}
return false
}
var usageTemplate = `Bhojpur Web CLI utility is a fast and flexible tool for managing your Bhojpur Web application.
You are using CLI utility for Bhojpur Web v2.x. If you are working on Bhojpur Web v1.x, please downgrade version to CLI v1.12.0
{{"USAGE" | headline}}
{{"webutl command [arguments]" | bold}}
{{"AVAILABLE COMMANDS" | headline}}
{{range .}}{{if .Runnable}}
{{.Name | printf "%-11s" | bold}} {{.Short}}{{end}}{{end}}
Use {{"webutl help [command]" | bold}} for more information about a command.
{{"ADDITIONAL HELP TOPICS" | headline}}
{{range .}}{{if not .Runnable}}
{{.Name | printf "%-11s"}} {{.Short}}{{end}}{{end}}
Use {{"webutl help [topic]" | bold}} for more information about that topic.
`
var helpTemplate = `{{"USAGE" | headline}}
{{.UsageLine | printf "webutl %s" | bold}}
{{if .Options}}{{endline}}{{"OPTIONS" | headline}}{{range $k,$v := .Options}}
{{$k | printf "-%s" | bold}}
{{$v}}
{{end}}{{end}}
{{"DESCRIPTION" | headline}}
{{tmpltostr .Long . | trim}}
`
var ErrorTemplate = `bhojpur: %s.
Use {{"webutl help" | bold}} for more information.
`
func Usage() {
utils.Tmpl(usageTemplate, commands.AvailableCommands)
}
func Help(args []string) {
if len(args) == 0 {
Usage()
return
}
if len(args) != 1 {
utils.PrintErrorAndExit("Too many arguments", ErrorTemplate)
}
arg := args[0]
for _, cmd := range commands.AvailableCommands {
if cmd.Name() == arg {
utils.Tmpl(helpTemplate, cmd)
return
}
}
utils.PrintErrorAndExit("Unknown help topic", ErrorTemplate)
}