@@ -21,7 +21,10 @@ import (
21
21
)
22
22
23
23
func projectCreate () * cobra.Command {
24
- return & cobra.Command {
24
+ var (
25
+ directory string
26
+ )
27
+ cmd := & cobra.Command {
25
28
Use : "create" ,
26
29
Short : "Create a project from the current directory" ,
27
30
RunE : func (cmd * cobra.Command , args []string ) error {
@@ -33,23 +36,17 @@ func projectCreate() *cobra.Command {
33
36
if err != nil {
34
37
return err
35
38
}
36
-
37
- workingDir , err := os .Getwd ()
38
- if err != nil {
39
- return err
40
- }
41
-
42
39
_ , err = runPrompt (cmd , & promptui.Prompt {
43
40
Default : "y" ,
44
41
IsConfirm : true ,
45
- Label : fmt .Sprintf ("Set up %s in your organization?" , color .New (color .FgHiCyan ).Sprintf ("%q" , workingDir )),
42
+ Label : fmt .Sprintf ("Set up %s in your organization?" , color .New (color .FgHiCyan ).Sprintf ("%q" , directory )),
46
43
})
47
44
if err != nil {
48
45
return err
49
46
}
50
47
51
48
name , err := runPrompt (cmd , & promptui.Prompt {
52
- Default : filepath .Base (workingDir ),
49
+ Default : filepath .Base (directory ),
53
50
Label : "What's your project's name?" ,
54
51
Validate : func (s string ) error {
55
52
_ , err = client .Project (cmd .Context (), organization .Name , s )
@@ -63,12 +60,12 @@ func projectCreate() *cobra.Command {
63
60
return err
64
61
}
65
62
66
- spin := spinner .New (spinner .CharSets [0 ], 50 * time .Millisecond )
63
+ spin := spinner .New (spinner .CharSets [0 ], 25 * time .Millisecond )
67
64
spin .Suffix = " Uploading current directory..."
68
65
spin .Start ()
69
66
defer spin .Stop ()
70
67
71
- bytes , err := tarDirectory (workingDir )
68
+ bytes , err := tarDirectory (directory )
72
69
if err != nil {
73
70
return err
74
71
}
@@ -84,6 +81,12 @@ func projectCreate() *cobra.Command {
84
81
Provisioner : database .ProvisionerTypeTerraform ,
85
82
// SkipResources on first import to detect variables defined by the project.
86
83
SkipResources : true ,
84
+ // ParameterValues: []coderd.CreateParameterValueRequest{{
85
+ // Name: "aws_access_key",
86
+ // SourceValue: "tomato",
87
+ // SourceScheme: database.ParameterSourceSchemeData,
88
+ // DestinationScheme: database.ParameterDestinationSchemeProvisionerVariable,
89
+ // }},
87
90
})
88
91
if err != nil {
89
92
return err
@@ -102,19 +105,85 @@ func projectCreate() *cobra.Command {
102
105
_ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s %s\n " , color .HiGreenString ("[parse]" ), log .Output )
103
106
}
104
107
108
+ _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "Parsed project source... displaying parameters:" )
109
+
105
110
schemas , err := client .ProvisionerJobParameterSchemas (cmd .Context (), organization .Name , job .ID )
106
111
if err != nil {
107
112
return err
108
113
}
109
114
115
+ values , err := client .ProvisionerJobParameterValues (cmd .Context (), organization .Name , job .ID )
116
+ if err != nil {
117
+ return err
118
+ }
119
+ valueBySchemaID := map [string ]coderd.ComputedParameterValue {}
120
+ for _ , value := range values {
121
+ valueBySchemaID [value .SchemaID .String ()] = value
122
+ }
123
+
110
124
for _ , schema := range schemas {
111
- fmt .Printf ("Schema: %+v\n " , schema )
125
+ if value , ok := valueBySchemaID [schema .ID .String ()]; ok {
126
+ fmt .Printf ("Value for: %s %s\n " , value .Name , value .SourceValue )
127
+ continue
128
+ }
129
+ fmt .Printf ("No value for: %s\n " , schema .Name )
112
130
}
113
131
132
+ // schemas, err := client.ProvisionerJobParameterSchemas(cmd.Context(), organization.Name, job.ID)
133
+ // if err != nil {
134
+ // return err
135
+ // }
136
+ // _, _ = fmt.Fprintf(cmd.OutOrStdout(), "\n %s\n\n", color.HiBlackString("Parameters"))
137
+
138
+ // for _, param := range params {
139
+ // if param.Value == nil {
140
+ // _, _ = fmt.Fprintf(cmd.OutOrStdout(), " %s = must be set\n", color.HiRedString(param.Schema.Name))
141
+ // continue
142
+ // }
143
+ // value := param.Value.DestinationValue
144
+ // if !param.Schema.RedisplayValue {
145
+ // value = "<redacted>"
146
+ // }
147
+ // output := fmt.Sprintf(" %s = %s", color.HiGreenString(param.Value.SourceValue), color.CyanString(value))
148
+ // param.Value.DefaultSourceValue = false
149
+ // param.Value.Scope = database.ParameterScopeOrganization
150
+ // param.Value.ScopeID = organization.ID
151
+ // if param.Value.DefaultSourceValue {
152
+ // output += " (default value)"
153
+ // } else {
154
+ // output += fmt.Sprintf(" (inherited from %s)", param.Value.Scope)
155
+ // }
156
+ // root := treeprint.NewWithRoot(output)
157
+ // root.AddNode(color.HiBlackString("Description") + "\n" + param.Schema.Description)
158
+ // fmt.Fprintln(cmd.OutOrStdout(), strings.Join(strings.Split(root.String(), "\n"), "\n "))
159
+ // }
160
+
161
+ // for _, param := range params {
162
+ // if param.Value != nil {
163
+ // continue
164
+ // }
165
+
166
+ // value, err := runPrompt(cmd, &promptui.Prompt{
167
+ // Label: "Specify value for " + color.HiCyanString(param.Schema.Name),
168
+ // Validate: func(s string) error {
169
+ // // param.Schema.Vali
170
+ // return nil
171
+ // },
172
+ // })
173
+ // if err != nil {
174
+ // continue
175
+ // }
176
+ // fmt.Printf(": %s\n", value)
177
+ // }
178
+
114
179
_ , _ = fmt .Fprintf (cmd .OutOrStdout (), "Create project %q!\n " , name )
115
180
return nil
116
181
},
117
182
}
183
+ currentDirectory , _ := os .Getwd ()
184
+ cmd .Flags ().StringVarP (& directory , "directory" , "d" , currentDirectory , "Specify the directory to create from" )
185
+
186
+ return cmd
118
187
}
119
188
120
189
func tarDirectory (directory string ) ([]byte , error ) {
0 commit comments