mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: Update CLI to handle managed variables (#6220)
* WIP * hcl * useManagedVariables * fix * Fix * Fix * fix * go:build * Fix * fix: bool flag * Insert template variables * API * fix * Expose via API * More wiring * CLI for testing purposes * WIP * Delete FIXME * planVars * WIP * WIP * UserVariableValues * no dry run * Dry run * Done FIXME * Fix * Fix: CLI * Fix: migration * API tests * Test info * Tests * More tests * fix: lint * Fix: authz * Address PR comments * Fix * fix * fix * CLI: create * unit tests: create templates with variables * Use last variables * Fix * Fix * Fix * Push tests * fix: variable is required if Default is nil * WIP * Redact sensitive values * Fixes * Fixes * Fix: arg description * Fix * Variable param * Fix: gen * Fix * Fix: goldens
This commit is contained in:
@@ -2,6 +2,7 @@ package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
"gopkg.in/yaml.v3"
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
"github.com/coder/coder/codersdk"
|
||||
)
|
||||
|
||||
func loadVariableValues(variablesFile string) ([]codersdk.VariableValue, error) {
|
||||
func loadVariableValuesFromFile(variablesFile string) ([]codersdk.VariableValue, error) {
|
||||
var values []codersdk.VariableValue
|
||||
if variablesFile == "" {
|
||||
return values, nil
|
||||
@@ -48,3 +49,19 @@ func createVariablesMapFromFile(variablesFile string) (map[string]string, error)
|
||||
}
|
||||
return variablesMap, nil
|
||||
}
|
||||
|
||||
func loadVariableValuesFromOptions(variables []string) ([]codersdk.VariableValue, error) {
|
||||
var values []codersdk.VariableValue
|
||||
for _, keyValue := range variables {
|
||||
split := strings.SplitN(keyValue, "=", 2)
|
||||
if len(split) < 2 {
|
||||
return nil, xerrors.Errorf("format key=value expected, but got %s", keyValue)
|
||||
}
|
||||
|
||||
values = append(values, codersdk.VariableValue{
|
||||
Name: split[0],
|
||||
Value: split[1],
|
||||
})
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user