Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions cmd/context/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,7 @@ func (cmd *DeleteCmd) Run(ctx context.Context, context string) error {
}

delete(devsyConfig.Contexts, context)
if devsyConfig.DefaultContext == context {
devsyConfig.DefaultContext = "default"
}
if devsyConfig.OriginalContext == context {
devsyConfig.OriginalContext = "default"
}
resetContextReferences(devsyConfig, context)

err = config.SaveConfig(devsyConfig)
if err != nil {
Expand All @@ -80,6 +75,15 @@ func (cmd *DeleteCmd) Run(ctx context.Context, context string) error {
return nil
}

func resetContextReferences(devsyConfig *config.Config, context string) {
if devsyConfig.DefaultContext == context {
devsyConfig.DefaultContext = "default"
}
if devsyConfig.OriginalContext == context {
devsyConfig.OriginalContext = "default"
}
}

// deleteContextSecrets aborts (rather than orphaning stored values) if the store
// is unavailable or a delete fails, so the deletion can be retried intact.
func deleteContextSecrets(devsyConfig *config.Config, contextName string) error {
Expand Down
71 changes: 40 additions & 31 deletions cmd/context/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,42 +60,51 @@ func (cmd *OptionsCmd) Run(ctx context.Context, args []string) error {
}
switch mode {
case output.ModePlain:
tableEntries := [][]string{}
for _, entry := range config.ContextOptions {
value := entryOptions[entry.Name].Value

tableEntries = append(tableEntries, []string{
entry.Name,
entry.Description,
entry.Default,
value,
})
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
printContextOptionsPlain(entryOptions)
case output.ModeJSON:
return printContextOptionsJSON(entryOptions)
}

return nil
}

func printContextOptionsPlain(entryOptions map[string]config.OptionValue) {
tableEntries := [][]string{}
for _, entry := range config.ContextOptions {
value := entryOptions[entry.Name].Value

tableEntries = append(tableEntries, []string{
entry.Name,
entry.Description,
entry.Default,
value,
})
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
})

table.Print([]string{
"Name",
"Description",
"Default",
"Value",
}, tableEntries)
case output.ModeJSON:
options := map[string]optionWithValue{}
for _, entry := range config.ContextOptions {
options[entry.Name] = optionWithValue{
ContextOption: entry,
Value: entryOptions[entry.Name].Value,
}
}
table.Print([]string{
"Name",
"Description",
"Default",
"Value",
}, tableEntries)
}

out, err := json.MarshalIndent(options, "", " ")
if err != nil {
return err
func printContextOptionsJSON(entryOptions map[string]config.OptionValue) error {
options := map[string]optionWithValue{}
for _, entry := range config.ContextOptions {
options[entry.Name] = optionWithValue{
ContextOption: entry,
Value: entryOptions[entry.Name].Value,
}
fmt.Print(string(out))
}

out, err := json.MarshalIndent(options, "", " ")
if err != nil {
return err
}
fmt.Print(string(out)) //nolint:forbidigo // CLI stdout output
return nil
}
67 changes: 38 additions & 29 deletions cmd/ide/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,40 +59,49 @@ func (cmd *ListCmd) Run(ctx context.Context) error {
}
switch mode {
case output.ModePlain:
tableEntries := [][]string{}
for _, entry := range ideparse.AllowedIDEs {
marker := ""
if devsyConfig.Current().DefaultIDE == string(entry.Name) {
marker = "*"
}
tableEntries = append(tableEntries, []string{
string(entry.Name),
marker,
})
printIDEsPlain(devsyConfig)
case output.ModeJSON:
return printIDEsJSON(devsyConfig)
}

return nil
}

func printIDEsPlain(devsyConfig *config.Config) {
tableEntries := [][]string{}
for _, entry := range ideparse.AllowedIDEs {
marker := ""
if devsyConfig.Current().DefaultIDE == string(entry.Name) {
marker = "*"
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
tableEntries = append(tableEntries, []string{
string(entry.Name),
marker,
})
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
})

table.Print([]string{
"Name",
"Default",
}, tableEntries)
case output.ModeJSON:
ides := []IDEWithDefault{}
for _, entry := range ideparse.AllowedIDEs {
ides = append(ides, IDEWithDefault{
AllowedIDE: entry,
Default: devsyConfig.Current().DefaultIDE == string(entry.Name),
})
}
table.Print([]string{
"Name",
"Default",
}, tableEntries)
}

out, err := json.MarshalIndent(ides, "", " ")
if err != nil {
return err
}
_, _ = fmt.Fprintln(os.Stdout, string(out))
func printIDEsJSON(devsyConfig *config.Config) error {
ides := []IDEWithDefault{}
for _, entry := range ideparse.AllowedIDEs {
ides = append(ides, IDEWithDefault{
AllowedIDE: entry,
Default: devsyConfig.Current().DefaultIDE == string(entry.Name),
})
}

out, err := json.MarshalIndent(ides, "", " ")
if err != nil {
return err
}
_, _ = fmt.Fprintln(os.Stdout, string(out))
return nil
}
69 changes: 39 additions & 30 deletions cmd/ide/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,41 +64,50 @@ func (cmd *OptionsCmd) Run(ctx context.Context, ide string) error {
}
switch mode {
case output.ModePlain:
tableEntries := [][]string{}
for optionName, entry := range ideOptions {
value := values[optionName].Value
tableEntries = append(tableEntries, []string{
optionName,
entry.Description,
entry.Default,
value,
})
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
printIDEOptionsPlain(ideOptions, values)
case output.ModeJSON:
return printIDEOptionsJSON(ideOptions, values)
}

return nil
}

func printIDEOptionsPlain(ideOptions ide.Options, values map[string]config.OptionValue) {
tableEntries := [][]string{}
for optionName, entry := range ideOptions {
value := values[optionName].Value
tableEntries = append(tableEntries, []string{
optionName,
entry.Description,
entry.Default,
value,
})
}
sort.SliceStable(tableEntries, func(i, j int) bool {
return tableEntries[i][0] < tableEntries[j][0]
})

table.Print([]string{
"Name",
"Description",
"Default",
"Value",
}, tableEntries)
case output.ModeJSON:
options := map[string]optionWithValue{}
for optionName, entry := range ideOptions {
options[optionName] = optionWithValue{
Option: entry,
Value: values[optionName].Value,
}
}
table.Print([]string{
"Name",
"Description",
"Default",
"Value",
}, tableEntries)
}

out, err := json.MarshalIndent(options, "", " ")
if err != nil {
return err
func printIDEOptionsJSON(ideOptions ide.Options, values map[string]config.OptionValue) error {
options := map[string]optionWithValue{}
for optionName, entry := range ideOptions {
options[optionName] = optionWithValue{
Option: entry,
Value: values[optionName].Value,
}
_, _ = fmt.Fprintln(os.Stdout, string(out))
}

out, err := json.MarshalIndent(options, "", " ")
if err != nil {
return err
}
_, _ = fmt.Fprintln(os.Stdout, string(out))
return nil
}
Loading
Loading