-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.go
63 lines (55 loc) · 2.08 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package cmd
import (
"github.com/spf13/cobra"
)
var configCmd = &cobra.Command{
Use: "config",
Short: "Manage your snipkit configuration file",
}
var configInitCommand = &cobra.Command{
Use: "init",
Short: "Initializes the snipkit config",
Long: `A snipkit configuration file will be generated at a default location best suited for your operation system.
Snipkit will try to detect any supported snippet manager application and configure them accordingly.`,
Run: func(cmd *cobra.Command, args []string) {
getConfigServiceFromContext(cmd.Context()).Create()
},
}
var configCleanCommand = &cobra.Command{
Use: "clean",
Short: "Deletes the snipkit config",
Long: `The snipkit configuration file will be deleted. You have to initialize a new configuration before using snipkit again.
This command is helpful if your configuration file is corrupted or you want to prepare the uninstalling snipkit.`,
Run: func(cmd *cobra.Command, args []string) {
getConfigServiceFromContext(cmd.Context()).Clean()
},
}
var configEditCommand = &cobra.Command{
Use: "edit",
Short: "Edit the snipkit config",
Long: `The snipkit configuration file will opened in your preferred editor.
The editor is defined by the $VISUAL or $EDITOR environment variables. Alternatively,
the editor can also be defined via the snipkit config file. If neither of those are
present, vim is used.`,
RunE: func(cmd *cobra.Command, args []string) error {
getConfigServiceFromContext(cmd.Context()).Edit()
return nil
},
}
var configMigrateCommand = &cobra.Command{
Use: "migrate",
Short: "Migrate the snipkit config",
Long: `The snipkit configuration file will be migrated to the latest version.
This command will do nothing if the version of the config file is already up-to-date.`,
RunE: func(cmd *cobra.Command, args []string) error {
getConfigServiceFromContext(cmd.Context()).Migrate()
return nil
},
}
func init() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(configInitCommand)
configCmd.AddCommand(configEditCommand)
configCmd.AddCommand(configMigrateCommand)
configCmd.AddCommand(configCleanCommand)
}