diff --git a/cmd/cmd.go b/cmd/cmd.go index c2fd4ac..c977e72 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -39,7 +39,8 @@ func Init() *cobra.Command { Short: "cornucopia run a code generation script.", Long: `cornucopia run a code generation script, find more details at : https://github.com/dvaumoron/cornucopia`, - Args: cobra.ExactArgs(1), + Version: "v1.1.0", + Args: cobra.ExactArgs(1), RunE: func(_ *cobra.Command, args []string) error { if err != nil { return err @@ -50,6 +51,14 @@ https://github.com/dvaumoron/cornucopia`, thread := &starlark.Thread{Name: common.Prefix + scriptname, Load: loader.Load} glu.InitCornucopiaGlobals() + if conf.Verbose { + fmt.Println("Use the repository", conf.RepoPath, "as local cache") + fmt.Println("Use the url", conf.RepoUrl, "as base to download script") + if conf.ForceDownload { + fmt.Println("Skip local cache in script resolution (still write in it)") + } + } + _, err = starlark.ExecFile(thread, scriptname, nil, nil) generated := len(glu.GeneratedFilenames) != 0 if err != nil { @@ -72,6 +81,7 @@ https://github.com/dvaumoron/cornucopia`, cmdFlags.StringVar(&conf.RepoPath, "repo-path", defaultRepoPath, "Local path of the script cache repository") cmdFlags.StringVar(&conf.RepoUrl, "repo-addr", defaultRepoUrl, "Address of the shared script repository") cmdFlags.BoolVarP(&conf.ForceDownload, "force-download", "f", false, "Force download in module resolution") + cmdFlags.BoolVarP(&conf.Verbose, "verbose", "v", false, "Verbose output") return cmd } diff --git a/config/config.go b/config/config.go index d560349..30ee2ae 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Config struct { RepoPath string RepoUrl string ForceDownload bool + Verbose bool } func InitDefault(envRepoPathName string, envRepoUrlName string) (string, string, error) { diff --git a/module/module.go b/module/module.go index 0c3cae2..5b4d15b 100644 --- a/module/module.go +++ b/module/module.go @@ -21,6 +21,7 @@ package module import ( "crypto/tls" "errors" + "fmt" "io" "net/http" "net/url" @@ -85,11 +86,20 @@ func (ml ModuleLoader) read(modulename string) ([]byte, error) { return data, err } + verbose := ml.conf.Verbose + if verbose { + fmt.Println("Failed to resolve", modulename, "from current directory :", err) + } + modulePath := path.Join(ml.conf.RepoPath, modulename) if !ml.conf.ForceDownload { if data, err = os.ReadFile(modulePath); err == nil { return data, nil } + + if verbose { + fmt.Println("Failed to resolve", modulename, "from", modulePath, ":", err) + } } moduleUrl, err := url.JoinPath(ml.conf.RepoUrl, modulename)