1
1
package cmd
2
2
3
3
import (
4
+ "asdf/config"
5
+ "asdf/plugins"
4
6
"log"
5
7
"os"
6
8
@@ -14,6 +16,9 @@ Manage all your runtime versions with one tool!
14
16
Complete documentation is available at https://asdf-vm.com/`
15
17
16
18
func Execute () {
19
+ logger := log .New (os .Stderr , "" , 0 )
20
+ log .SetFlags (0 )
21
+
17
22
app := & cli.App {
18
23
Name : "asdf" ,
19
24
Version : "0.1.0" ,
@@ -39,14 +44,18 @@ func Execute() {
39
44
& cli.Command {
40
45
Name : "add" ,
41
46
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 ))
44
54
},
45
55
},
46
56
& cli.Command {
47
57
Name : "list" ,
48
58
Action : func (cCtx * cli.Context ) error {
49
- log .Print ("Bim" )
50
59
return nil
51
60
},
52
61
},
@@ -81,3 +90,22 @@ func Execute() {
81
90
log .Fatal (err )
82
91
}
83
92
}
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