This repository was archived by the owner on Aug 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 605
Expand file tree
/
Copy pathhelp.go
More file actions
202 lines (173 loc) · 5.98 KB
/
Copy pathhelp.go
File metadata and controls
202 lines (173 loc) · 5.98 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package main
import (
"fmt"
"koding/klientctl/config"
"github.com/codegangsta/cli"
)
// cmdDescriptions is the help text shown to user. Note in addition to adding
// new text here you'll need to update main.go to use the description.
var cmdDescriptions = map[string]string{
"install": fmtDesc(
"<authToken>",
fmt.Sprintf("Install the %s. sudo is required.", config.KlientName),
),
"compat-mount": fmtDesc(
"[optional args] <alias:remote path> <local folder>",
fmt.Sprintf(`Mount folder from remote machine to local folder.
Alias is the local identifer for machine in 'kd list'.
Local folder can be relative or absolute path, if
folder doesn't exit, it'll be created.
By default this uses FUSE to mount remote folders.
For best I/O performance, especially with commands
that does a lot of filesystem operations like git,
use --oneway-sync.`),
),
"mount": fmtDesc(
"(<machine-identifier>:<remote-path> <local-path> | <command>) [<options>...]",
`Mount <remote-path> from remote machine to <local-path>.
With <machine-identifier> argument, kd machine mount identifies requested machine.
Either machine ID, machine alias or IP can be used as identifier and all of them
can by obtained by running "kd machine list" command.
<local-path> can be relative or absolute, if the folder does not exit, it will be created.`,
),
"exec": fmtDesc(
"(<local-mount-path> | @<machine-id>) <command> [<args>...]",
`Run <command> on a remote machine specified by either @<machine-id> or <local-mount-path>.
If <local-mount-path> is provided, kd is going to look up a remote machine
by reading the remote source of the mount. The mount must be active and
the remote end on-line.
In order to run a <command> on a remote machine that has no local mounts,
use @<machine-id> argument instead.`,
),
"ssh": fmtDesc(
"<alias>", "SSH into the machine.",
),
"compat-unmount": fmtDesc(
"<alias>",
"Unmount folder which was previously mounted.",
),
"umount": fmtDesc(
"(<mount-id> | <mount-path>)...",
"Unmount existing mounts.",
),
"remount": fmtDesc(
"<alias>",
"Remount machine which was previously mounted using the same settings.",
),
"run": fmtDesc(
"<command> <arguments>",
fmt.Sprintf(`Run command on remote or local machine depending
on the location where the command was run.
All arguments after run are passed to command on
remote machine.
Currently only commands that don't require tty/pty
work on remote machines.`),
),
"list": fmtDesc(
"", "List running machines for user.",
),
"restart": fmtDesc(
"", fmt.Sprintf("Restart the %s.", config.KlientName),
),
"stop": fmtDesc(
"", fmt.Sprintf("Stop the %s.", config.KlientName),
),
"start": fmtDesc(
"", fmt.Sprintf("Start the %s.", config.KlientName),
),
"status": fmtDesc(
"", fmt.Sprintf("Check status of the %s.", config.KlientName),
),
"uninstall": fmtDesc(
"", fmt.Sprintf("Uninstall the %s.", config.KlientName),
),
"update": fmtDesc(
"", fmt.Sprintf("Update %s to latest version.", config.KlientName),
),
"version": fmtDesc(
"", fmt.Sprintf("Display version information of the %s.", config.KlientName),
),
"autocompletion": fmtDesc(
"[optional args] <shellname>",
`Install autocompletion files for the given shell, to enable
autocompletion with kd`,
),
"sync": fmtDesc(
"[optional args] <machineName> <remote-to-local|local-to-remote>",
"Manually sync a OneWaySync Mount, in either direction.",
),
"compat-cp": fmtDesc(
"[optional args] <source> <destination>",
`Copy a file from the source to the destination, either remote to local or local
to remote.
Like with mounting, remote paths are referred to with the
machineName:path/to/file syntax. Example:
kd cp ./sourceFile apple:destinationFile
kd cp apple:sourceFile ./destinationFile
`,
),
"cp": fmtDesc(
"[<machine-identifier>:]<source-path> [<machine-identifier>:]<destination-path>",
`Copy file(s) from <source-path> to the <destination-path>.
Either <source-path> or <destination-path> must contain <machine-identifier>. Thus,
it's not possible to copy files between two remote machines.
If <destination-path> doesn't exist, it will be created.`,
),
"open": fmtDesc(
"[optional args] <file1> [file2] [file3]",
`Open a file on the Koding UI, if the given machine is visible on Koding.
`,
),
}
func init() {
cli.AppHelpTemplate = `
USAGE:
{{.Name}} command [command options]
COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
{{end}}
`
cli.CommandHelpTemplate = `USAGE:
kd {{.FullName}}{{if .Description}} {{.Description}}{{else if .Usage}} - {{.Usage}}{{end}}{{if .Flags}}
OPTIONS:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
cli.SubcommandHelpTemplate = `NAME:
{{.HelpName}} - {{.Usage}}
USAGE:
{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}} {{if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{end}}{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}
{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
}
// fixDescription is a hacky way of dealing with current CLI package. The
// problem is that for codegangsta subcommands .Usage field holds value defined
// in .Description field and the real .Usage value is ignored. This makes
// the CLI API invalid when we need to print proper help description.
func fixDescription(usage string) func() {
tmp := cli.SubcommandHelpTemplate
cli.SubcommandHelpTemplate = `NAME:
{{.HelpName}} - ` + usage + `
USAGE:
{{.HelpName}} {{.Usage}}
COMMANDS:{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{end}}{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}
{{end}}{{if .VisibleFlags}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
return func() {
cli.SubcommandHelpTemplate = tmp
}
}
func fmtDesc(opts, description string) string {
return fmt.Sprintf("%s\n\nDESCRIPTION\n %s\n", opts, description)
}