summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorMatt Holt <mholt@users.noreply.github.com>2021-01-04 11:11:56 -0700
committerGitHub <noreply@github.com>2021-01-04 11:11:56 -0700
commit144b65cf993f7078cccee9e1e119d18537922b81 (patch)
tree0b70aa66e6e56c1f5c8dbebc1b197aa864de27a6 /cmd
parentc8557dc00bd93ce8ecf0bb724856a320e129c71b (diff)
cmd: Organize list-modules output; --packages flag (#3925)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/commandfuncs.go71
-rw-r--r--cmd/commands.go3
2 files changed, 62 insertions, 12 deletions
diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go
index 20c662b..25cbe58 100644
--- a/cmd/commandfuncs.go
+++ b/cmd/commandfuncs.go
@@ -360,12 +360,37 @@ func cmdBuildInfo(fl Flags) (int, error) {
}
func cmdListModules(fl Flags) (int, error) {
+ packages := fl.Bool("packages")
versions := fl.Bool("versions")
+ type moduleInfo struct {
+ caddyModuleID string
+ goModule *debug.Module
+ err error
+ }
+ printModuleInfo := func(mi moduleInfo) {
+ fmt.Print(mi.caddyModuleID)
+ if versions && mi.goModule != nil {
+ fmt.Print(" " + mi.goModule.Version)
+ }
+ if packages && mi.goModule != nil {
+ fmt.Print(" " + mi.goModule.Path)
+ if mi.goModule.Replace != nil {
+ fmt.Print(" => " + mi.goModule.Replace.Path)
+ }
+ }
+ if mi.err != nil {
+ fmt.Printf(" [%v]", mi.err)
+ }
+ fmt.Println()
+ }
+
+ // organize modules by whether they come with the standard distribution
+ var standard, nonstandard, unknown []moduleInfo
+
bi, ok := debug.ReadBuildInfo()
- if !ok || !versions {
- // if there's no build information,
- // just print out the modules
+ if !ok {
+ // oh well, just print the module IDs and exit
for _, m := range caddy.Modules() {
fmt.Println(m)
}
@@ -375,8 +400,8 @@ func cmdListModules(fl Flags) (int, error) {
for _, modID := range caddy.Modules() {
modInfo, err := caddy.GetModule(modID)
if err != nil {
- // that's weird
- fmt.Println(modID)
+ // that's weird, shouldn't happen
+ unknown = append(unknown, moduleInfo{caddyModuleID: modID, err: err})
continue
}
@@ -404,15 +429,39 @@ func cmdListModules(fl Flags) (int, error) {
}
}
- // if we could find no matching module, just print out
- // the module ID instead
- if matched == nil {
- fmt.Println(modID)
- continue
+ caddyModGoMod := moduleInfo{caddyModuleID: modID, goModule: matched}
+
+ if strings.HasPrefix(modPkgPath, caddy.ImportPath) {
+ standard = append(standard, caddyModGoMod)
+ } else {
+ nonstandard = append(nonstandard, caddyModGoMod)
}
+ }
- fmt.Printf("%s %s\n", modID, matched.Version)
+ if len(standard) > 0 {
+ for _, mod := range standard {
+ printModuleInfo(mod)
+ }
+ }
+ fmt.Printf("\n Standard modules: %d\n", len(standard))
+ if len(nonstandard) > 0 {
+ if len(standard) > 0 {
+ fmt.Println()
+ }
+ for _, mod := range nonstandard {
+ printModuleInfo(mod)
+ }
+ }
+ fmt.Printf("\n Non-standard modules: %d\n", len(nonstandard))
+ if len(unknown) > 0 {
+ if len(standard) > 0 || len(nonstandard) > 0 {
+ fmt.Println()
+ }
+ for _, mod := range unknown {
+ printModuleInfo(mod)
+ }
}
+ fmt.Printf("\n Unknown modules: %d\n", len(unknown))
return caddy.ExitCodeSuccess, nil
}
diff --git a/cmd/commands.go b/cmd/commands.go
index ea8402d..e4a2b91 100644
--- a/cmd/commands.go
+++ b/cmd/commands.go
@@ -191,10 +191,11 @@ config file; otherwise the default is assumed.`,
RegisterCommand(Command{
Name: "list-modules",
Func: cmdListModules,
- Usage: "[--versions]",
+ Usage: "[--packages] [--versions]",
Short: "Lists the installed Caddy modules",
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("list-modules", flag.ExitOnError)
+ fs.Bool("packages", false, "Print package paths")
fs.Bool("versions", false, "Print version information")
return fs
}(),