Skip to content

Commit 605414e

Browse files
authored
[envsec] Move envcli to envsec/pkg (#173)
## Summary This is needed by launchpad ## How was it tested?
1 parent 090d910 commit 605414e

File tree

14 files changed

+28
-16
lines changed

14 files changed

+28
-16
lines changed

envsec/cmd/envsec/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"context"
88
"os"
99

10-
"go.jetpack.io/envsec/internal/envcli"
10+
"go.jetpack.io/envsec/pkg/envcli"
1111
)
1212

1313
func main() {
File renamed without changes.

envsec/internal/envcli/download.go renamed to envsec/pkg/envcli/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type downloadCmdFlags struct {
2121
format string
2222
}
2323

24-
func downloadCmd() *cobra.Command {
24+
func DownloadCmd() *cobra.Command {
2525
flags := &downloadCmdFlags{}
2626
command := &cobra.Command{
2727
Use: "download <file1>",

envsec/internal/envcli/exec.go renamed to envsec/pkg/envcli/exec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type execCmdFlags struct {
1818
configFlags
1919
}
2020

21-
func execCmd() *cobra.Command {
21+
func ExecCmd() *cobra.Command {
2222
flags := &execCmdFlags{}
2323
command := &cobra.Command{
2424
Use: "exec <command>",

envsec/internal/envcli/flags.go renamed to envsec/pkg/envcli/flags.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,16 @@ func (f *configFlags) validateProjectID(orgID typeids.OrganizationID) (string, e
7575
return config.ProjectID.String(), nil
7676
}
7777

78-
type cmdConfig struct {
78+
type CmdConfig struct {
7979
Store envsec.Store
8080
EnvID envsec.EnvID
8181
}
8282

83-
func (f *configFlags) genConfig(ctx context.Context) (*cmdConfig, error) {
83+
func (f *configFlags) genConfig(ctx context.Context) (*CmdConfig, error) {
84+
if bootstrappedConfig != nil {
85+
return bootstrappedConfig, nil
86+
}
87+
8488
var tok *session.Token
8589
var err error
8690

@@ -128,8 +132,16 @@ func (f *configFlags) genConfig(ctx context.Context) (*cmdConfig, error) {
128132
return nil, errors.WithStack(err)
129133
}
130134

131-
return &cmdConfig{
135+
return &CmdConfig{
132136
Store: store,
133137
EnvID: envid,
134138
}, nil
135139
}
140+
141+
var bootstrappedConfig *CmdConfig
142+
143+
// BootstrapConfig is used to set the config for all commands that use genConfig
144+
// Useful for using envsec programmatically.
145+
func BootstrapConfig(cmdConfig *CmdConfig) {
146+
bootstrappedConfig = cmdConfig
147+
}
File renamed without changes.

envsec/internal/envcli/ls.go renamed to envsec/pkg/envcli/ls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type listCmdFlags struct {
1919
Format string
2020
}
2121

22-
func listCmd() *cobra.Command {
22+
func ListCmd() *cobra.Command {
2323
flags := &listCmdFlags{}
2424

2525
command := &cobra.Command{

envsec/internal/envcli/rm.go renamed to envsec/pkg/envcli/rm.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type removeCmdFlags struct {
1616
configFlags
1717
}
1818

19-
func removeCmd() *cobra.Command {
19+
func RemoveCmd() *cobra.Command {
2020
flags := &removeCmdFlags{}
2121
command := &cobra.Command{
2222
Use: "rm <NAME1> [<NAME2>]...",

envsec/internal/envcli/root.go renamed to envsec/pkg/envcli/root.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ func RootCmd(flags *rootCmdFlags) *cobra.Command {
5252
command.Flag("json-errors").Hidden = true
5353

5454
command.AddCommand(authCmd())
55-
command.AddCommand(downloadCmd())
56-
command.AddCommand(execCmd())
55+
command.AddCommand(DownloadCmd())
56+
command.AddCommand(ExecCmd())
5757
command.AddCommand(initCmd())
58-
command.AddCommand(listCmd())
59-
command.AddCommand(removeCmd())
60-
command.AddCommand(setCmd())
61-
command.AddCommand(uploadCmd())
58+
command.AddCommand(ListCmd())
59+
command.AddCommand(RemoveCmd())
60+
command.AddCommand(SetCmd())
61+
command.AddCommand(UploadCmd())
6262
command.SetUsageFunc(UsageFunc)
6363
return command
6464
}
File renamed without changes.

0 commit comments

Comments
 (0)