Skip to content

Commit da824ae

Browse files
committed
Bring back config get and config set
1 parent 981db06 commit da824ae

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"github.com/gitpod-io/local-app/pkg/config"
9+
"github.com/gitpod-io/local-app/pkg/prettyprint"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var configGetCmd = &cobra.Command{
14+
Use: "get",
15+
Short: "Get an individual config value in the config file",
16+
RunE: func(cmd *cobra.Command, args []string) error {
17+
cmd.SilenceUsage = true
18+
19+
cfg := config.FromContext(cmd.Context())
20+
21+
return WriteTabular([]struct {
22+
Telemetry bool `header:"Telemetry"`
23+
Autoupdate bool `header:"Autoupdate"`
24+
}{
25+
{Telemetry: cfg.Telemetry.Enabled, Autoupdate: cfg.Autoupdate},
26+
}, configGetOpts.Format, prettyprint.WriterFormatNarrow)
27+
},
28+
}
29+
30+
var configGetOpts struct {
31+
Format formatOpts
32+
}
33+
34+
func init() {
35+
configCmd.AddCommand(configGetCmd)
36+
addFormatFlags(configGetCmd, &configGetOpts.Format)
37+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) 2023 Gitpod GmbH. All rights reserved.
2+
// Licensed under the GNU Affero General Public License (AGPL).
3+
// See License.AGPL.txt in the project root for license information.
4+
5+
package cmd
6+
7+
import (
8+
"log/slog"
9+
10+
"github.com/gitpod-io/local-app/pkg/config"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
var configSetCmd = &cobra.Command{
15+
Use: "set",
16+
Short: "Set an individual config value in the config file",
17+
Long: `Set an individual config value in the config file.
18+
19+
Example:
20+
# Disable telemetry
21+
local-app config set --telemetry=false
22+
23+
# Disable autoupdate
24+
local-app config set --autoupdate=false
25+
26+
# Enable telemetry and autoupdate
27+
local-app config set --telemetry=true --autoupdate=true
28+
`,
29+
RunE: func(cmd *cobra.Command, args []string) error {
30+
cmd.SilenceUsage = true
31+
32+
var update bool
33+
cfg := config.FromContext(cmd.Context())
34+
if cmd.Flags().Changed("autoupdate") {
35+
cfg.Autoupdate = configSetOpts.Autoupdate
36+
update = true
37+
}
38+
if cmd.Flags().Changed("telemetry") {
39+
cfg.Telemetry.Enabled = configSetOpts.Telemetry
40+
update = true
41+
}
42+
if !update {
43+
return cmd.Help()
44+
}
45+
46+
slog.Debug("updating config")
47+
err := config.SaveConfig(cfg.Filename, cfg)
48+
if err != nil {
49+
return err
50+
}
51+
return nil
52+
},
53+
}
54+
55+
var configSetOpts struct {
56+
Autoupdate bool
57+
Telemetry bool
58+
}
59+
60+
func init() {
61+
configCmd.AddCommand(configSetCmd)
62+
configSetCmd.Flags().BoolVar(&configSetOpts.Autoupdate, "autoupdate", true, "enable/disable autoupdate")
63+
configSetCmd.Flags().BoolVar(&configSetOpts.Telemetry, "telemetry", true, "enable/disable telemetry")
64+
}

0 commit comments

Comments
 (0)