Skip to content

Commit 3bbc1ac

Browse files
committed
Add --osmconfig flag
1 parent 8f987a6 commit 3bbc1ac

File tree

15 files changed

+56
-49
lines changed

15 files changed

+56
-49
lines changed

pkg/cmds/config/current.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ func newCmdCurrent() *cobra.Command {
1818
cmd.Help()
1919
os.Exit(1)
2020
}
21-
currentContext()
21+
currentContext(otx.GetConfigPath(cmd))
2222
},
2323
}
2424
return setCmd
2525
}
2626

27-
func currentContext() {
28-
config, err := otx.LoadConfig()
27+
func currentContext(configPath string) {
28+
config, err := otx.LoadConfig(configPath)
2929
term.ExitOnError(err)
3030

3131
term.Infoln(config.CurrentContext)

pkg/cmds/config/get.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ func newCmdGet() *cobra.Command {
1919
cmd.Help()
2020
os.Exit(1)
2121
}
22-
getContexts()
22+
getContexts(otx.GetConfigPath(cmd))
2323
},
2424
}
2525
return setCmd
2626
}
2727

28-
func getContexts() {
29-
config, err := otx.LoadConfig()
28+
func getContexts(configPath string) {
29+
config, err := otx.LoadConfig(configPath)
3030
term.ExitOnError(err)
3131

3232
table := tablewriter.NewWriter(os.Stdout)

pkg/cmds/config/set.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func newCmdSet() *cobra.Command {
5454
}
5555

5656
req.Name = args[0]
57-
setContext(req)
57+
setContext(req, otx.GetConfigPath(cmd))
5858
},
5959
}
6060
setCmd.Flags().StringVar(&req.Provider, "provider", "", "Cloud storage provider")
@@ -83,7 +83,7 @@ func newCmdSet() *cobra.Command {
8383
return setCmd
8484
}
8585

86-
func setContext(req *setContextRequest) {
86+
func setContext(req *setContextRequest, configPath string) {
8787
nc := &otx.Context{
8888
Name: req.Name,
8989
Provider: req.Provider,
@@ -149,7 +149,7 @@ func setContext(req *setContextRequest) {
149149
term.Fatalln("Unknown provider:" + req.Provider)
150150
}
151151

152-
config, _ := otx.LoadConfig()
152+
config, _ := otx.LoadConfig(configPath)
153153
if config == nil {
154154
config = &otx.OSMConfig{
155155
Contexts: make([]*otx.Context, 0),
@@ -168,6 +168,6 @@ func setContext(req *setContextRequest) {
168168
config.Contexts = append(config.Contexts, nc)
169169
}
170170
config.CurrentContext = req.Name
171-
err := config.Save()
171+
err := config.Save(configPath)
172172
term.ExitOnError(err)
173173
}

pkg/cmds/config/use.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ func newCmdUse() *cobra.Command {
2424
}
2525

2626
name := args[0]
27-
useContex(name)
27+
useContex(name, otx.GetConfigPath(cmd))
2828
},
2929
}
3030
return setCmd
3131
}
3232

33-
func useContex(name string) {
34-
config, err := otx.LoadConfig()
33+
func useContex(name, configPath string) {
34+
config, err := otx.LoadConfig(configPath)
3535
term.ExitOnError(err)
3636

3737
if config.CurrentContext == name {
@@ -50,6 +50,6 @@ func useContex(name string) {
5050
}
5151

5252
config.CurrentContext = name
53-
err = config.Save()
53+
err = config.Save(configPath)
5454
term.ExitOnError(err)
5555
}

pkg/cmds/config/view.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ func newCmdView() *cobra.Command {
1919
cmd.Help()
2020
os.Exit(1)
2121
}
22-
viewContext()
22+
viewContext(otx.GetConfigPath(cmd))
2323
},
2424
}
2525
return setCmd
2626
}
2727

28-
func viewContext() {
29-
config, err := otx.LoadConfig()
28+
func viewContext(configPath string) {
29+
config, err := otx.LoadConfig(configPath)
3030
term.ExitOnError(err)
3131

3232
data, err := yaml.Marshal(config)

pkg/cmds/lc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,16 @@ func NewCmdListContainers() *cobra.Command {
2626
os.Exit(1)
2727
}
2828

29-
listContainers(req)
29+
listContainers(req, otx.GetConfigPath(cmd))
3030
},
3131
}
3232

3333
cmd.Flags().StringVarP(&req.context, "context", "", "", "Name of osmconfig context to use")
3434
return cmd
3535
}
3636

37-
func listContainers(req *containerListRequest) {
38-
cfg, err := otx.LoadConfig()
37+
func listContainers(req *containerListRequest, configPath string) {
38+
cfg, err := otx.LoadConfig(configPath)
3939
term.ExitOnError(err)
4040

4141
loc, err := cfg.Dial(req.context)

pkg/cmds/ls.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewCmdListIetms() *cobra.Command {
3434
}
3535

3636
req.container = args[0]
37-
listItems(req)
37+
listItems(req, otx.GetConfigPath(cmd))
3838
},
3939
}
4040

@@ -44,8 +44,8 @@ func NewCmdListIetms() *cobra.Command {
4444
return cmd
4545
}
4646

47-
func listItems(req *itemListRequest) {
48-
cfg, err := otx.LoadConfig()
47+
func listItems(req *itemListRequest, configPath string) {
48+
cfg, err := otx.LoadConfig(configPath)
4949
term.ExitOnError(err)
5050

5151
loc, err := cfg.Dial(req.context)

pkg/cmds/mc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ func NewCmdMakeContainer() *cobra.Command {
3030
}
3131

3232
req.container = args[0]
33-
makeContainer(req)
33+
makeContainer(req, otx.GetConfigPath(cmd))
3434
},
3535
}
3636

3737
cmd.Flags().StringVarP(&req.context, "context", "", "", "Name of osmconfig context to use")
3838
return cmd
3939
}
4040

41-
func makeContainer(req *containerMakeRequest) {
42-
cfg, err := otx.LoadConfig()
41+
func makeContainer(req *containerMakeRequest, configPath string) {
42+
cfg, err := otx.LoadConfig(configPath)
4343
term.ExitOnError(err)
4444

4545
loc, err := cfg.Dial(req.context)

pkg/cmds/pull.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func NewCmdPull() *cobra.Command {
3636

3737
req.srcID = args[0]
3838
req.destPath = args[1]
39-
pull(req)
39+
pull(req, otx.GetConfigPath(cmd))
4040
},
4141
}
4242

@@ -45,8 +45,8 @@ func NewCmdPull() *cobra.Command {
4545
return cmd
4646
}
4747

48-
func pull(req *itemPullRequest) {
49-
cfg, err := otx.LoadConfig()
48+
func pull(req *itemPullRequest, configPath string) {
49+
cfg, err := otx.LoadConfig(configPath)
5050
term.ExitOnError(err)
5151

5252
loc, err := cfg.Dial(req.context)

pkg/cmds/push.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func NewCmdPush() *cobra.Command {
3535

3636
req.srcPath = args[0]
3737
req.destID = args[1]
38-
push(req)
38+
push(req, otx.GetConfigPath(cmd))
3939
},
4040
}
4141

@@ -44,8 +44,8 @@ func NewCmdPush() *cobra.Command {
4444
return cmd
4545
}
4646

47-
func push(req *itemPushRequest) {
48-
cfg, err := otx.LoadConfig()
47+
func push(req *itemPushRequest, configPath string) {
48+
cfg, err := otx.LoadConfig(configPath)
4949
term.ExitOnError(err)
5050

5151
loc, err := cfg.Dial(req.context)

0 commit comments

Comments
 (0)