From 588d8dd206da2179d645e30dc7c2d62be3424728 Mon Sep 17 00:00:00 2001 From: Sergey Rubanov Date: Wed, 26 Jun 2024 01:21:06 +0200 Subject: [PATCH] improve usage info --- cli/init.go | 152 ++++++++++++++++++++++++++++------------------------ 1 file changed, 83 insertions(+), 69 deletions(-) diff --git a/cli/init.go b/cli/init.go index cbbad50..340b0c2 100644 --- a/cli/init.go +++ b/cli/init.go @@ -16,25 +16,20 @@ import ( ) const ( - githubTarballURL = "https://github.com/dispatchrun/%s/tarball/main" - githubAPIURL = "https://api.github.com/repos/dispatchrun/%s/branches/main" - repo = "dispatch-examples" + githubTarballURL = "https://github.com/%s/tarball/main" + githubAPIURL = "https://api.github.com/repos/%s/branches/main" + repo = "dispatchrun/dispatch-examples" dispatchUserDir = "dispatch" ) -// TODO: versioning for different SDKs? - func directoryExists(path string) (bool, error) { info, err := os.Stat(path) if os.IsNotExist(err) { - // The directory does not exist return false, nil } if err != nil { - // Some other error occurred return false, err } - // Check if the path is a directory return info.IsDir(), nil } @@ -96,6 +91,8 @@ func extractTarball(r io.Reader, destDir string) error { continue } + // We need to strip the top-level directory from the file paths + // It contains the repository name and the commit SHA which we don't need // Get the top-level directory name if topLevelDir == "" { parts := strings.Split(header.Name, "/") @@ -283,73 +280,27 @@ func copyFile(srcFile string, dstFile string) error { } func initCommand() *cobra.Command { + dispatchUserDirPath, err := getAppDataDir(dispatchUserDir) + if err != nil { + fmt.Printf("failed to get Dispatch templates directory: %s", err) + } + + dispatchTemplatesDirPath := filepath.Join(dispatchUserDirPath, "templates") + dispatchTemplatesHashPath := filepath.Join(dispatchUserDirPath, "templates.sha") + templates := []string{} + cmd := &cobra.Command{ Use: "init