gohugoio / hugo

The world’s fastest framework for building websites.
https://gohugo.io
Apache License 2.0
75k stars 7.47k forks source link

Command "hugo mod get -u" does not accept global --source flag #12539

Open fmunteanu opened 4 months ago

fmunteanu commented 4 months ago

What version of Hugo are you using (hugo version)?

$ hugo version
hugo v0.126.1+extended darwin/arm64 BuildDate=2024-05-15T10:42:34Z VendorInfo=brew

Does this issue reproduce with the latest release?

Yes.

Issue

Running the Hugo module update does not accept the global --source flag:

$ hugo mod get -s ./docs -u
flag provided but not defined: -s
usage: go get [-t] [-u] [-v] [build flags] [packages]
Run 'go help get' for details.
Error: failed to get ["-d" "-s" "./docs" "-u"]: failed to execute 'go [get -d -s ./docs -u]': failed to execute binary "go" with args [get -d -s ./docs -u]: flag provided but not defined: -s
usage: go get [-t] [-u] [-v] [build flags] [packages]
Run 'go help get' for details.
 *errors.errorString

$ hugo mod get --source ./docs -u
flag provided but not defined: -source
usage: go get [-t] [-u] [-v] [build flags] [packages]
Run 'go help get' for details.
Error: failed to get ["-d" "--source" "./docs" "-u"]: failed to execute 'go [get -d --source ./docs -u]': failed to execute binary "go" with args [get -d --source ./docs -u]: flag provided but not defined: -source
usage: go get [-t] [-u] [-v] [build flags] [packages]
Run 'go help get' for details.
 *errors.errorString

I'm wondering if this is the expected behaviour, since the help clearly states I can use that flag:

Usage:
  hugo mod get [flags] [args]

Flags:
  -h, --help   help for get

Global Flags:
      --clock string               set the clock used by Hugo, e.g. --clock 2021-11-06T22:30:00.00+09:00
      --config string              config file (default is hugo.yaml|json|toml)
      --configDir string           config dir (default "config")
      --debug                      debug output
  -d, --destination string         filesystem path to write files to
  -e, --environment string         build environment
      --ignoreVendorPaths string   ignores any _vendor for module paths matching the given Glob pattern
      --logLevel string            log level (debug|info|warn|error)
      --quiet                      build in quiet mode
      --renderToMemory             render to memory (mostly useful when running the server)
  -s, --source string              filesystem path to read files relative from
      --themesDir string           filesystem path to themes directory
  -v, --verbose                    verbose output

The recursive update works as intended:

$ hugo mod get -u ./...
Update module in /Users/floren/github/website/docs
Update module in /Users/floren/github/website/global

There are no issues running hugo mod tidy -s ./docs, for example.

jmooring commented 4 months ago

This has come up before but we didn't log an issue:

https://discourse.gohugo.io/t/quiet-down-hugo-mod-get/47747/2

bep commented 4 months ago

I'm wondering if this is the expected behaviour, since the help clearly states I can use that flag:

No, but the hugo mod get command is a little special. We have a few tools that depends on external programs (e.g. go) that currently doesn't work well with the --source flag. I have never used the --source flag myself, so it's not on my "top 10" list of things to fix.

bep commented 4 months ago

I did a quick check now, and we do set the Cmd.Dir to the value of --source when running the go commands via os/exec, so this should work if we fixed the flag handling.