mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 09:42:34 +02:00
add "add-default-config" flag
Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com>
This commit is contained in:
@@ -31,6 +31,7 @@ func main() {
|
||||
flagVersion = flag.BoolP("version", "v", false, "print version")
|
||||
flagProject = flag.StringP("project", "P", "", `project name to open directly, or "tmp" for a temporary session`)
|
||||
flagAddDefaultPlugins = flag.Bool("add-default-plugins", false, "copy built-in example plugins into the plugins dir and exit")
|
||||
flagAddDefaultConfig = flag.Bool("add-default-config", false, "copy the default config file to the config path and exit")
|
||||
)
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
flag.Usage = func() {
|
||||
@@ -66,6 +67,19 @@ func main() {
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *flagAddDefaultConfig {
|
||||
cfgPath := filepath.Join(os.Getenv("HOME"), ".config", "spilltea", "config.yaml")
|
||||
if *flagConfig != "" {
|
||||
cfgPath = *flagConfig
|
||||
}
|
||||
if err := config.WriteDefaultConfig(cfgPath); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "add-default-config: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf("default config written to %s\n", cfgPath)
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if *flagProject != "" && !homeUI.IsValidProjectName(*flagProject) {
|
||||
fmt.Fprintf(os.Stderr, "project: invalid name %q (only lowercase letters, digits, - and _ are allowed)\n", *flagProject)
|
||||
os.Exit(1)
|
||||
|
||||
Reference in New Issue
Block a user