diff --git a/framework/tooling/downloadtemplate/main.go b/framework/tooling/downloadtemplate/main.go index b139dc3..19b54ba 100644 --- a/framework/tooling/downloadtemplate/main.go +++ b/framework/tooling/downloadtemplate/main.go @@ -1,7 +1,7 @@ package main import ( - "bufio" + "flag" "fmt" "os" "os/exec" @@ -41,22 +41,23 @@ func deleteAllExceptTemplate(outPath string, excludeDir string) { func main() { cwd, _ := os.Getwd() - var outPath string - reader := bufio.NewReader(os.Stdin) - fmt.Print("What should we call your new app? Enter name: ") - outPath, _ = reader.ReadString('\n') - outPath = strings.ReplaceAll(outPath, "\n", "") - outPath = strings.ReplaceAll(outPath, " ", "-") - outPath = strings.ToLower(outPath) - if outPath == "" { + outPath := flag.String("out", "", "Specify the output path for the new app") + + flag.Parse() + + *outPath = strings.ReplaceAll(*outPath, "\n", "") + *outPath = strings.ReplaceAll(*outPath, " ", "-") + *outPath = strings.ToLower(*outPath) + + if *outPath == "" { fmt.Println("Please provide a name for your app.") return } excludeDir := "starter-template" - install := exec.Command("git", "clone", "https://github.com/maddalax/mhtml", "--depth=1", outPath) + install := exec.Command("git", "clone", "https://github.com/maddalax/mhtml", "--depth=1", *outPath) install.Stdout = os.Stdout install.Stderr = os.Stderr err := install.Run() @@ -66,9 +67,9 @@ func main() { return } - deleteAllExceptTemplate(outPath, excludeDir) + deleteAllExceptTemplate(*outPath, excludeDir) - newDir := filepath.Join(cwd, outPath) + newDir := filepath.Join(cwd, *outPath) mvCmd := exec.Command("cp", "-vaR", fmt.Sprintf("%s/.", excludeDir), ".") mvCmd.Dir = newDir diff --git a/framework/tooling/mhtml/Taskfile.yml b/framework/tooling/mhtml/Taskfile.yml index a6d698c..29ef183 100644 --- a/framework/tooling/mhtml/Taskfile.yml +++ b/framework/tooling/mhtml/Taskfile.yml @@ -4,15 +4,11 @@ interval: 500ms tasks: - template2: + template: dir: '{{.USER_WORKING_DIR}}' desc: Generate template from source code cmds: - - | - echo "Type value of FOO:" - read FOO; - echo "You said: ${FOO}"; - - go run github.com/maddalax/mhtml/framework/tooling/downloadtemplate@latest + - go run github.com/maddalax/mhtml/framework/tooling/downloadtemplate@latest -out my-app setup: deps: [copy-framework-assets, ast]