From 802292ed72346535269accfd05f2e2cf8dedd2be Mon Sep 17 00:00:00 2001 From: Aylur Date: Thu, 14 Nov 2024 13:15:31 +0000 Subject: [PATCH] fix #616 --- cmd/init.go | 37 +++++++++++++++---------------------- flake.nix | 2 +- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/cmd/init.go b/cmd/init.go index d4e7a4b1..f9fcb705 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -21,7 +21,7 @@ var initCommand = &cobra.Command{ Short: "Initialize a project directory", Long: `Initialize a project directory by setting up files needed by TypeScript, generating types and setting up a basic bar example`, - Args: cobra.MaximumNArgs(1), + Args: cobra.NoArgs, Run: initConfig, } @@ -47,32 +47,25 @@ func initConfig(cmd *cobra.Command, args []string) { lib.Err("currently only gtk3 is supported") } - var configDir string - if len(args) > 0 { - var err error - configDir, err = filepath.Abs(args[0]) - if err != nil { - lib.Err(err) - } - } else { - configDir = defaultConfigDir() + _, err := filepath.Abs(initDirectory) + if err != nil { + lib.Err(err) } - - if info, err := os.Stat(configDir); err == nil && info.IsDir() && !force { - lib.Err("could not initialize: " + lib.Cyan(configDir) + " already exists") + if info, err := os.Stat(initDirectory); err == nil && info.IsDir() && !force { + lib.Err("could not initialize: " + lib.Cyan(initDirectory) + " already exists") } tsconf := strings.ReplaceAll(getDataFile("tsconfig.json"), "@ASTAL_GJS@", astalGjs) tsconf = strings.ReplaceAll(tsconf, "@GTK_VERSION@", "gtk3") - lib.Mkdir(configDir + "/widget") + lib.Mkdir(initDirectory + "/widget") - lib.WriteFile(configDir+"/.gitignore", "@girs/\nnode_modules/") - lib.WriteFile(configDir+"/tsconfig.json", tsconf) - lib.WriteFile(configDir+"/env.d.ts", getDataFile("env.d.ts")) - lib.WriteFile(configDir+"/style.scss", getDataFile("style.scss")) - lib.WriteFile(configDir+"/widget/Bar.tsx", getDataFile("gtk3/Bar.tsx")) - lib.WriteFile(configDir+"/app.ts", getDataFile("gtk3/app.ts")) + lib.WriteFile(initDirectory+"/.gitignore", "@girs/\nnode_modules/") + lib.WriteFile(initDirectory+"/tsconfig.json", tsconf) + lib.WriteFile(initDirectory+"/env.d.ts", getDataFile("env.d.ts")) + lib.WriteFile(initDirectory+"/style.scss", getDataFile("style.scss")) + lib.WriteFile(initDirectory+"/widget/Bar.tsx", getDataFile("gtk3/Bar.tsx")) + lib.WriteFile(initDirectory+"/app.ts", getDataFile("gtk3/app.ts")) - genTypes(configDir, "*") - fmt.Println(lib.Green("project ready") + " at " + lib.Cyan(configDir)) + genTypes(initDirectory, "*") + fmt.Println(lib.Green("project ready") + " at " + lib.Cyan(initDirectory)) } diff --git a/flake.nix b/flake.nix index 9dd4fc2b..94f64c6e 100644 --- a/flake.nix +++ b/flake.nix @@ -44,7 +44,7 @@ welcomeText = '' # Getting Started - run `nix develop` to enter the development environment - - run `ags init . -f` to setup an initial ags project + - run `ags init -d . -f` to setup an initial ags project - run `ags run .` to run the project ''; };