This repository has been archived by the owner on Mar 26, 2024. It is now read-only.
/
prepare.cmdr.go
142 lines (124 loc) · 4 KB
/
prepare.cmdr.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright © 2020 Hedzr Yeh.
package svr
import (
"github.com/hedzr/cmdr"
"github.com/hedzr/cmdr-addons/pkg/plugins/dex"
"github.com/hedzr/cmdr-addons/pkg/svr/tls"
"time"
)
func (d *daemonImpl) OnCmdrPrepare(prog *dex.Program, root *cmdr.RootCommand) (err error) {
serverCmd := root.FindSubCommand("server")
serverStartCmd := serverCmd.FindSubCommand("start")
opt := cmdr.NewCmdFrom(serverCmd)
if flg := serverCmd.FindFlag("port"); flg != nil {
flg.DefaultValue = defaultPort
} else {
cmdr.NewInt(defaultPort).Titles("port", "p").
Description("the port to listen.", "").
Group("").
Placeholder("PORT").
AttachTo(opt)
}
ox := cmdr.NewCmdFrom(serverStartCmd)
cmdr.NewBool(false).
Titles("socket", "se").
Description("enable the listening on unix sock", "").
Group("Unix Sock").
AttachTo(ox)
cmdr.NewString("").
Titles("socket-file", "sf").
Description("the listening unix sock file (/var/run/app/app.sock)", "").
Placeholder("FILE").
Group("Unix Sock").
AttachTo(ox)
cmdr.NewBool(false).
Titles("reset-socket-file", "").
Description("unlink/delete the residual unix sock file at first (for the abnormal terminated)", "").
Group("Unix Sock").
AttachTo(ox)
// Server-Type radio group
cmdr.NewBool(true).
Titles("h2-server", "h2", "").
Description("start as a HTTP/2 server", "").
ToggleGroup("Server-Type").
AttachTo(ox)
cmdr.NewBool(false).
Titles("cmdexec-loop", "lp").
Description("start a worker and loop for cmd exec", "").
ToggleGroup("Server-Type").
AttachTo(ox)
//
certOptCmd := cmdr.NewSubCmd().Titles("certs", "ca").
Description("certificates operations...", "").
Group("CA").
AttachTo(opt)
certCreateCmd := cmdr.NewSubCmd().Titles("create", "c").
Description("create CA, server and client certificates").
Action(tls.CertCreate).
AttachTo(certOptCmd)
cmdr.NewStringSlice().Titles("host", "h").
Description("Comma-separated hostnames and IPs to generate a certificate for").
Placeholder("HOSTNAMES,...").
AttachTo(certCreateCmd)
cmdr.NewString().Titles("start-date", "f", "from", "valid-from").
Description("Creation date formatted as Jan 1 15:04:05 2011 (default now)").
Placeholder("DATETIME").
AttachTo(certCreateCmd)
cmdr.NewDuration(365*10*24*time.Hour).Titles("valid-for", "duration", "d").
Description("Duration that certificate is valid for").
AttachTo(certCreateCmd)
cmdr.NewString().Titles("CN", "cn", "common-name").
Description("common name string").
Placeholder("CN").
AttachTo(certCreateCmd)
// caCmd := certOptCmd.NewSubCommand("ca").
// Description("certification tool (such as create-ca, create-cert, ...)", "certification tool (such as create-ca, create-cert, ... )\nverbose long descriptions here.").
// Group("CA")
//
// caCreateCmd := caCmd.NewSubCommand("create", "c").
// Description("create NEW CA certification", "").
// Group("Tool").
// Action(tls.CaCreate)
cmdr.NewBool(false).
Titles("iris", "iris").
Description("use Iris engine", "").
ToggleGroup("Mux").
AttachTo(opt)
cmdr.NewBool(true).
Titles("gin", "gin").
Description("use Gin engine", "").
ToggleGroup("Mux").
AttachTo(opt)
cmdr.NewBool(false).
Titles("gorilla", "gorilla").
Description("use Gorilla engine", "").
ToggleGroup("Mux").
AttachTo(opt)
cmdr.NewBool(false).
Titles("echo", "echo").
Description("use Echo engine", "").
ToggleGroup("Mux").
AttachTo(opt)
cmdr.NewBool(false).
Titles("std", "std").
Description("use stdlib http.ServerMux engine", "").
ToggleGroup("Mux").
AttachTo(opt)
// http 2 client
cmdr.NewSubCmd().
Titles("h2-test", "h2").
Description("test http 2 client", "test http 2 client,\nverbose long descriptions here.").
Group("Test").
Action(func(cmd *cmdr.Command, args []string) (err error) {
// runClient()
return
}).
AttachToRoot(root)
return
}
func (d *daemonImpl) BeforeServiceStart(prog *dex.Program, root *cmdr.Command) (err error) {
return
}
func (d *daemonImpl) AfterServiceStop(prog *dex.Program, root *cmdr.Command) (err error) {
return
}