Skip to content

Commit 26b91aa

Browse files
committed
feat(golang-rewrite): create pluginAddCommand function for plugin add command action
1 parent 43f2058 commit 26b91aa

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

cmd/main.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cmd
22

33
import (
4+
"asdf/config"
5+
"asdf/plugins"
46
"log"
57
"os"
68

@@ -14,6 +16,9 @@ Manage all your runtime versions with one tool!
1416
Complete documentation is available at https://asdf-vm.com/`
1517

1618
func Execute() {
19+
logger := log.New(os.Stderr, "", 0)
20+
log.SetFlags(0)
21+
1722
app := &cli.App{
1823
Name: "asdf",
1924
Version: "0.1.0",
@@ -39,14 +44,18 @@ func Execute() {
3944
&cli.Command{
4045
Name: "add",
4146
Action: func(cCtx *cli.Context) error {
42-
log.Print("Baz")
43-
return nil
47+
args := cCtx.Args()
48+
conf, err := config.LoadConfig()
49+
if err != nil {
50+
logger.Printf("error loading config: %s", err)
51+
}
52+
53+
return pluginAddCommand(cCtx, conf, logger, args.Get(0), args.Get(1))
4454
},
4555
},
4656
&cli.Command{
4757
Name: "list",
4858
Action: func(cCtx *cli.Context) error {
49-
log.Print("Bim")
5059
return nil
5160
},
5261
},
@@ -81,3 +90,22 @@ func Execute() {
8190
log.Fatal(err)
8291
}
8392
}
93+
94+
func pluginAddCommand(cCtx *cli.Context, conf config.Config, logger *log.Logger, pluginName, pluginRepo string) error {
95+
if pluginName == "" {
96+
// Invalid arguments
97+
// Maybe one day switch this to show the generated help
98+
// cli.ShowSubcommandHelp(cCtx)
99+
return cli.Exit("usage: asdf plugin add <name> [<git-url>]", 1)
100+
} else if pluginRepo == "" {
101+
// add from plugin repo
102+
// TODO: implement
103+
return cli.Exit("Not implemented yet", 1)
104+
} else {
105+
err := plugins.PluginAdd(conf, pluginName, pluginRepo)
106+
if err != nil {
107+
logger.Printf("error adding plugin: %s", err)
108+
}
109+
}
110+
return nil
111+
}

0 commit comments

Comments
 (0)