mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
feat: Add "coder projects create" command (#246)
* Refactor parameter parsing to return nil values if none computed * Refactor parameter to allow for hiding redisplay * Refactor parameters to enable schema matching * Refactor provisionerd to dynamically update parameter schemas * Refactor job update for provisionerd * Handle multiple states correctly when provisioning a project * Add project import job resource table * Basic creation flow works! * Create project fully works!!! * Only show job status if completed * Add create workspace support * Replace Netflix/go-expect with ActiveState * Fix linting errors * Use forked chzyer/readline * Add create workspace CLI * Add CLI test * Move jobs to their own APIs * Remove go-expect * Fix requested changes * Skip workspacecreate test on windows
This commit is contained in:
@ -1,14 +1,22 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/xlab/treeprint"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/coder/coder/coderd"
|
||||
"github.com/coder/coder/database"
|
||||
)
|
||||
|
||||
func projects() *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "projects",
|
||||
Long: "Testing something",
|
||||
Use: "projects",
|
||||
Aliases: []string{"project"},
|
||||
Example: `
|
||||
- Create a project for developers to create workspaces
|
||||
|
||||
@ -28,3 +36,46 @@ func projects() *cobra.Command {
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func displayProjectImportInfo(cmd *cobra.Command, parameterSchemas []coderd.ParameterSchema, parameterValues []coderd.ComputedParameterValue, resources []coderd.ProjectImportJobResource) error {
|
||||
schemaByID := map[string]coderd.ParameterSchema{}
|
||||
for _, schema := range parameterSchemas {
|
||||
schemaByID[schema.ID.String()] = schema
|
||||
}
|
||||
|
||||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "\n %s\n\n", color.HiBlackString("Parameters"))
|
||||
for _, value := range parameterValues {
|
||||
schema, ok := schemaByID[value.SchemaID.String()]
|
||||
if !ok {
|
||||
return xerrors.Errorf("schema not found: %s", value.Name)
|
||||
}
|
||||
displayValue := value.SourceValue
|
||||
if !schema.RedisplayValue {
|
||||
displayValue = "<redacted>"
|
||||
}
|
||||
output := fmt.Sprintf("%s %s %s", color.HiCyanString(value.Name), color.HiBlackString("="), displayValue)
|
||||
if value.DefaultSourceValue {
|
||||
output += " (default value)"
|
||||
} else if value.Scope != database.ParameterScopeImportJob {
|
||||
output += fmt.Sprintf(" (inherited from %s)", value.Scope)
|
||||
}
|
||||
|
||||
root := treeprint.NewWithRoot(output)
|
||||
if schema.Description != "" {
|
||||
root.AddBranch(fmt.Sprintf("%s\n%s", color.HiBlackString("Description"), schema.Description))
|
||||
}
|
||||
if schema.AllowOverrideSource {
|
||||
root.AddBranch(fmt.Sprintf("%s Users can customize this value!", color.HiYellowString("+")))
|
||||
}
|
||||
_, _ = fmt.Fprintln(cmd.OutOrStdout(), " "+strings.Join(strings.Split(root.String(), "\n"), "\n "))
|
||||
}
|
||||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), " %s\n\n", color.HiBlackString("Resources"))
|
||||
for _, resource := range resources {
|
||||
transition := color.HiGreenString("start")
|
||||
if resource.Transition == database.WorkspaceTransitionStop {
|
||||
transition = color.HiRedString("stop")
|
||||
}
|
||||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), " %s %s on %s\n\n", color.HiCyanString(resource.Type), color.HiCyanString(resource.Name), transition)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user