mirror of
https://github.com/anotherhadi/spilltea.git
synced 2026-05-20 01:32:33 +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")
|
flagVersion = flag.BoolP("version", "v", false, "print version")
|
||||||
flagProject = flag.StringP("project", "P", "", `project name to open directly, or "tmp" for a temporary session`)
|
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")
|
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.CommandLine.SetOutput(os.Stdout)
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
@@ -66,6 +67,19 @@ func main() {
|
|||||||
os.Exit(0)
|
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) {
|
if *flagProject != "" && !homeUI.IsValidProjectName(*flagProject) {
|
||||||
fmt.Fprintf(os.Stderr, "project: invalid name %q (only lowercase letters, digits, - and _ are allowed)\n", *flagProject)
|
fmt.Fprintf(os.Stderr, "project: invalid name %q (only lowercase letters, digits, - and _ are allowed)\n", *flagProject)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
@@ -74,6 +74,16 @@ func Load(path string) error {
|
|||||||
return viper.Unmarshal(Global)
|
return viper.Unmarshal(Global)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func WriteDefaultConfig(path string) error {
|
||||||
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
||||||
|
return fmt.Errorf("create config dir: %w", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(path, defaultConfig, 0o644); err != nil {
|
||||||
|
return fmt.Errorf("write config: %w", err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func ExpandPath(p string) string {
|
func ExpandPath(p string) string {
|
||||||
if strings.HasPrefix(p, "~/") {
|
if strings.HasPrefix(p, "~/") {
|
||||||
home, err := os.UserHomeDir()
|
home, err := os.UserHomeDir()
|
||||||
|
|||||||
+2
-2
@@ -2,8 +2,8 @@ pre-commit:
|
|||||||
piped: true
|
piped: true
|
||||||
commands:
|
commands:
|
||||||
inject-exec-basics:
|
inject-exec-basics:
|
||||||
glob: "docs/basics.md"
|
glob: "{docs/basics.md,cmd/**}"
|
||||||
run: python3 .github/scripts/inject-exec.py {staged_files}
|
run: python3 .github/scripts/inject-exec.py docs/basics.md
|
||||||
stage_fixed: true
|
stage_fixed: true
|
||||||
inject-exec:
|
inject-exec:
|
||||||
glob: "README.md"
|
glob: "README.md"
|
||||||
|
|||||||
Reference in New Issue
Block a user