Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 8f4a73c

Browse files
committed
fixup! Migrate envs
1 parent b2c08eb commit 8f4a73c

File tree

5 files changed

+88
-206
lines changed

5 files changed

+88
-206
lines changed

ci/integration/integration_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestCoderCLI(t *testing.T) {
3434
tcli.StderrEmpty(),
3535
)
3636

37-
c.Run(ctx, "coder version").Assert(t,
37+
c.Run(ctx, "coder --version").Assert(t,
3838
tcli.StderrEmpty(),
3939
tcli.Success(),
4040
tcli.StdoutMatches("linux"),

cmd/coder/main.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,15 @@ import (
99
"runtime"
1010

1111
"cdr.dev/coder-cli/internal/x/xterminal"
12-
"github.com/spf13/pflag"
1312
"github.com/urfave/cli"
1413

15-
cdrcli "go.coder.com/cli"
1614
"go.coder.com/flog"
1715
)
1816

1917
var (
2018
version string = "unknown"
2119
)
2220

23-
type rootCmd struct{}
24-
25-
func (r *rootCmd) Run(fl *pflag.FlagSet) {
26-
27-
fl.Usage()
28-
}
29-
30-
func (r *rootCmd) Spec() cdrcli.CommandSpec {
31-
return cdrcli.CommandSpec{
32-
Name: "coder",
33-
Usage: "[subcommand] [flags]",
34-
Desc: "coder provides a CLI for working with an existing Coder Enterprise installation.",
35-
}
36-
}
37-
38-
func (r *rootCmd) Subcommands() []cdrcli.Command {
39-
return []cdrcli.Command{
40-
&syncCmd{},
41-
&urlsCmd{},
42-
}
43-
}
44-
4521
func main() {
4622
if os.Getenv("PPROF") != "" {
4723
go func() {
@@ -67,6 +43,7 @@ func main() {
6743
makeConfigSSHCmd(),
6844
makeSecretsCmd(),
6945
makeEnvsCommand(),
46+
makeSyncCmd(),
7047
}
7148
err = app.Run(os.Args)
7249
if err != nil {

cmd/coder/secrets.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ func makeSecretsCmd() cli.Command {
1818
return cli.Command{
1919
Name: "secrets",
2020
Usage: "",
21-
Description: "interact with secrets",
21+
Description: "Interact with secrets objects owned by the active user.",
2222
Subcommands: []cli.Command{
2323
{
2424
Name: "ls",
2525
Usage: "",
26-
Description: "",
26+
Description: "list all secrets owned by the active user",
2727
Action: listSecrets,
2828
},
2929
makeCreateSecret(),
@@ -54,11 +54,12 @@ func makeCreateSecret() cli.Command {
5454

5555
return cli.Command{
5656
Name: "create",
57-
Usage: "",
58-
Description: "",
57+
Usage: "create a new secret",
58+
Description: "Create a new secret object to store application secrets and access them securely from within your environments.",
59+
ArgsUsage: "[secret_name]",
5960
Before: func(c *cli.Context) error {
6061
if c.Args().First() == "" {
61-
return xerrors.Errorf("[name] is a required field argument")
62+
return xerrors.Errorf("[secret_name] is a required argument")
6263
}
6364
if fromPrompt && (fromLiteral != "" || fromFile != "") {
6465
return xerrors.Errorf("--from-prompt cannot be set along with --from-file or --from-literal")

cmd/coder/sync.go

Lines changed: 80 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,37 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
"github.com/spf13/pflag"
11+
"cdr.dev/coder-cli/internal/sync"
12+
"github.com/urfave/cli"
13+
"golang.org/x/xerrors"
1214

13-
"go.coder.com/cli"
1415
"go.coder.com/flog"
15-
16-
"cdr.dev/coder-cli/internal/sync"
1716
)
1817

19-
type syncCmd struct {
20-
init bool
21-
}
22-
23-
func (cmd *syncCmd) Spec() cli.CommandSpec {
24-
return cli.CommandSpec{
25-
Name: "sync",
26-
Usage: "[local directory] [<env name>:<remote directory>]",
27-
Desc: "establish a one way directory sync to a remote environment",
18+
func makeSyncCmd() cli.Command {
19+
var init bool
20+
return cli.Command{
21+
Name: "sync",
22+
Usage: "synchronize local files to a Coder environment",
23+
Description: "Establish a one way directory sync to a Coder environment.",
24+
ArgsUsage: "[local directory] [<env name>:<remote directory>]",
25+
Before: func(c *cli.Context) error {
26+
if c.Args().Get(0) == "" || c.Args().Get(1) == "" {
27+
return xerrors.Errorf("[local] and [remote] arguments are required")
28+
}
29+
return nil
30+
},
31+
Action: makeRunSync(&init),
32+
Flags: []cli.Flag{
33+
cli.BoolFlag{
34+
Name: "init",
35+
Usage: "do initial transfer and exit",
36+
Destination: &init,
37+
},
38+
},
2839
}
2940
}
3041

31-
func (cmd *syncCmd) RegisterFlags(fl *pflag.FlagSet) {
32-
fl.BoolVarP(&cmd.init, "init", "i", false, "do initial transfer and exit")
33-
}
34-
3542
// version returns local rsync protocol version as a string.
3643
func rsyncVersion() string {
3744
cmd := exec.Command("rsync", "--version")
@@ -49,63 +56,61 @@ func rsyncVersion() string {
4956
return versionString[1]
5057
}
5158

52-
func (cmd *syncCmd) Run(fl *pflag.FlagSet) {
53-
var (
54-
local = fl.Arg(0)
55-
remote = fl.Arg(1)
56-
)
57-
if local == "" || remote == "" {
58-
exitUsage(fl)
59-
}
60-
61-
entClient := requireAuth()
62-
63-
info, err := os.Stat(local)
64-
if err != nil {
65-
flog.Fatal("%v", err)
66-
}
67-
if !info.IsDir() {
68-
flog.Fatal("%s must be a directory", local)
69-
}
70-
71-
remoteTokens := strings.SplitN(remote, ":", 2)
72-
if len(remoteTokens) != 2 {
73-
flog.Fatal("remote misformatted")
74-
}
75-
var (
76-
envName = remoteTokens[0]
77-
remoteDir = remoteTokens[1]
78-
)
79-
80-
env := findEnv(entClient, envName)
81-
82-
absLocal, err := filepath.Abs(local)
83-
if err != nil {
84-
flog.Fatal("make abs path out of %v: %v", local, absLocal)
85-
}
86-
87-
s := sync.Sync{
88-
Init: cmd.init,
89-
Env: env,
90-
RemoteDir: remoteDir,
91-
LocalDir: absLocal,
92-
Client: entClient,
93-
}
94-
95-
localVersion := rsyncVersion()
96-
remoteVersion, rsyncErr := s.Version()
97-
98-
if rsyncErr != nil {
99-
flog.Info("Unable to determine remote rsync version. Proceeding cautiously.")
100-
} else if localVersion != remoteVersion {
101-
flog.Fatal("rsync protocol mismatch: local = %v, remote = %v", localVersion, rsyncErr)
102-
}
103-
104-
for err == nil || err == sync.ErrRestartSync {
105-
err = s.Run()
106-
}
107-
108-
if err != nil {
109-
flog.Fatal("%v", err)
59+
func makeRunSync(init *bool) func(c *cli.Context) {
60+
return func(c *cli.Context) {
61+
var (
62+
local = c.Args().Get(0)
63+
remote = c.Args().Get(1)
64+
)
65+
66+
entClient := requireAuth()
67+
68+
info, err := os.Stat(local)
69+
if err != nil {
70+
flog.Fatal("%v", err)
71+
}
72+
if !info.IsDir() {
73+
flog.Fatal("%s must be a directory", local)
74+
}
75+
76+
remoteTokens := strings.SplitN(remote, ":", 2)
77+
if len(remoteTokens) != 2 {
78+
flog.Fatal("remote misformatted")
79+
}
80+
var (
81+
envName = remoteTokens[0]
82+
remoteDir = remoteTokens[1]
83+
)
84+
85+
env := findEnv(entClient, envName)
86+
87+
absLocal, err := filepath.Abs(local)
88+
if err != nil {
89+
flog.Fatal("make abs path out of %v: %v", local, absLocal)
90+
}
91+
92+
s := sync.Sync{
93+
Init: *init,
94+
Env: env,
95+
RemoteDir: remoteDir,
96+
LocalDir: absLocal,
97+
Client: entClient,
98+
}
99+
100+
localVersion := rsyncVersion()
101+
remoteVersion, rsyncErr := s.Version()
102+
103+
if rsyncErr != nil {
104+
flog.Info("Unable to determine remote rsync version. Proceeding cautiously.")
105+
} else if localVersion != remoteVersion {
106+
flog.Fatal("rsync protocol mismatch: local = %v, remote = %v", localVersion, rsyncErr)
107+
}
108+
109+
for err == nil || err == sync.ErrRestartSync {
110+
err = s.Run()
111+
}
112+
if err != nil {
113+
flog.Fatal("%v", err)
114+
}
110115
}
111116
}

internal/x/xvalidate/errors.go

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)