2018-09-24 07:53:16 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-19 03:09:09 +00:00
|
|
|
"strings"
|
2018-10-31 06:14:33 +00:00
|
|
|
|
2022-04-12 17:14:21 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2018-09-24 07:53:16 +00:00
|
|
|
"github.com/urfave/cli"
|
2021-09-22 17:33:41 +00:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/config"
|
2022-10-15 19:54:11 +00:00
|
|
|
"github.com/photoprism/photoprism/internal/get"
|
2022-04-12 17:14:21 +00:00
|
|
|
"github.com/photoprism/photoprism/pkg/report"
|
2018-09-24 07:53:16 +00:00
|
|
|
)
|
|
|
|
|
2022-04-14 10:30:47 +00:00
|
|
|
// ShowConfigCommand configures the command name, flags, and action.
|
2022-04-12 11:28:28 +00:00
|
|
|
var ShowConfigCommand = cli.Command{
|
2022-04-17 10:30:33 +00:00
|
|
|
Name: "config",
|
2022-05-10 18:47:45 +00:00
|
|
|
Usage: "Displays global config options and their current values",
|
2022-04-17 10:30:33 +00:00
|
|
|
Flags: report.CliFlags,
|
2022-04-12 11:28:28 +00:00
|
|
|
Action: showConfigAction,
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|
|
|
|
|
2022-10-12 12:57:33 +00:00
|
|
|
// ConfigReports specifies which configuration reports to display.
|
|
|
|
var ConfigReports = []Report{
|
2022-11-25 09:23:34 +00:00
|
|
|
{Title: "Global Config Options", NoWrap: true, Report: func(conf *config.Config) ([][]string, []string) {
|
2022-10-12 12:57:33 +00:00
|
|
|
return conf.Report()
|
|
|
|
}},
|
|
|
|
}
|
|
|
|
|
2022-04-14 10:30:47 +00:00
|
|
|
// showConfigAction shows global config option names and values.
|
2022-04-12 11:28:28 +00:00
|
|
|
func showConfigAction(ctx *cli.Context) error {
|
2019-05-06 21:18:10 +00:00
|
|
|
conf := config.NewConfig(ctx)
|
2022-04-12 17:14:21 +00:00
|
|
|
conf.SetLogLevel(logrus.FatalLevel)
|
2022-10-15 19:54:11 +00:00
|
|
|
get.SetConfig(conf)
|
2022-07-21 18:23:00 +00:00
|
|
|
|
|
|
|
if err := conf.Init(); err != nil {
|
|
|
|
log.Debug(err)
|
|
|
|
}
|
2018-09-24 07:53:16 +00:00
|
|
|
|
2022-10-12 12:57:33 +00:00
|
|
|
for _, rep := range ConfigReports {
|
|
|
|
// Get values.
|
|
|
|
rows, cols := rep.Report(conf)
|
2020-05-30 12:52:47 +00:00
|
|
|
|
2022-10-12 12:57:33 +00:00
|
|
|
// Render report.
|
|
|
|
opt := report.Options{Format: report.CliFormat(ctx), NoWrap: rep.NoWrap}
|
|
|
|
result, _ := report.Render(rows, cols, opt)
|
2021-10-05 20:33:29 +00:00
|
|
|
|
2022-10-12 12:57:33 +00:00
|
|
|
// Show report.
|
|
|
|
if opt.Format == report.Default {
|
2022-10-24 10:33:03 +00:00
|
|
|
fmt.Printf("\n%s\n\n", strings.ToUpper(rep.Title))
|
2022-10-12 12:57:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt.Println(result)
|
|
|
|
}
|
2022-04-17 10:30:33 +00:00
|
|
|
|
2022-10-12 12:57:33 +00:00
|
|
|
return nil
|
2018-09-24 07:53:16 +00:00
|
|
|
}
|