From 9e887be2d6bb07b2b49155b8935390c78d8bbff1 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 21 Dec 2018 04:32:17 +0100 Subject: [PATCH] Add version command, see #50 --- cmd/photoprism/photoprism.go | 1 + internal/commands/config.go | 26 +++++++++++++++++++++++--- internal/commands/config_test.go | 22 +++++++++------------- internal/commands/version.go | 23 +++++++++++++++++++++++ 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 internal/commands/version.go diff --git a/cmd/photoprism/photoprism.go b/cmd/photoprism/photoprism.go index 202638711..a5301e75e 100644 --- a/cmd/photoprism/photoprism.go +++ b/cmd/photoprism/photoprism.go @@ -20,6 +20,7 @@ func main() { app.Commands = []cli.Command{ commands.ConfigCommand, + commands.VersionCommand, commands.StartCommand, commands.MigrateCommand, commands.ImportCommand, diff --git a/internal/commands/config.go b/internal/commands/config.go index 970d7ef55..8c120c82a 100644 --- a/internal/commands/config.go +++ b/internal/commands/config.go @@ -20,14 +20,34 @@ func configAction(ctx *cli.Context) error { fmt.Printf("NAME VALUE\n") fmt.Printf("debug %t\n", conf.Debug()) fmt.Printf("config-file %s\n", conf.ConfigFile()) - fmt.Printf("darktable-cli %s\n", conf.DarktableCli()) + fmt.Printf("app-name %s\n", conf.AppName()) + fmt.Printf("app-version %s\n", conf.AppVersion()) + fmt.Printf("app-copyright %s\n", conf.AppCopyright()) + + fmt.Printf("database-driver %s\n", conf.DatabaseDriver()) + fmt.Printf("database-dsn %s\n", conf.DatabaseDsn()) + fmt.Printf("originals-path %s\n", conf.OriginalsPath()) fmt.Printf("import-path %s\n", conf.ImportPath()) fmt.Printf("export-path %s\n", conf.ExportPath()) fmt.Printf("cache-path %s\n", conf.CachePath()) fmt.Printf("assets-path %s\n", conf.AssetsPath()) - fmt.Printf("database-driver %s\n", conf.DatabaseDriver()) - fmt.Printf("database-dsn %s\n", conf.DatabaseDsn()) + fmt.Printf("thumbnails-path %s\n", conf.ThumbnailsPath()) + fmt.Printf("tf-model-path %s\n", conf.TensorFlowModelPath()) + fmt.Printf("templates-path %s\n", conf.HttpTemplatesPath()) + fmt.Printf("favicons-path %s\n", conf.HttpFaviconsPath()) + fmt.Printf("public-path %s\n", conf.HttpPublicPath()) + fmt.Printf("public-build-path %s\n", conf.HttpPublicBuildPath()) + + fmt.Printf("http-host %s\n", conf.HttpServerHost()) + fmt.Printf("http-port %d\n", conf.HttpServerPort()) + fmt.Printf("http-mode %s\n", conf.HttpServerMode()) + + fmt.Printf("sql-host %s\n", conf.SqlServerHost()) + fmt.Printf("sql-port %d\n", conf.SqlServerPort()) + fmt.Printf("sql-path %s\n", conf.SqlServerPath()) + + fmt.Printf("darktable-cli %s\n", conf.DarktableCli()) return nil } diff --git a/internal/commands/config_test.go b/internal/commands/config_test.go index f5c5d0607..6e5ac0e43 100644 --- a/internal/commands/config_test.go +++ b/internal/commands/config_test.go @@ -16,19 +16,15 @@ func TestConfigCommand(t *testing.T) { err = ConfigCommand.Run(ctx) }) - expected := `NAME VALUE -debug false -config-file /go/src/github.com/photoprism/photoprism/configs/photoprism.yml -darktable-cli /usr/bin/darktable-cli -originals-path /go/src/github.com/photoprism/photoprism/assets/testdata/originals -import-path /srv/photoprism/photos/import -export-path /srv/photoprism/photos/export -cache-path /srv/photoprism/cache -assets-path /go/src/github.com/photoprism/photoprism/assets -database-driver tidb -database-dsn root:@tcp(localhost:4000)/photoprism?parseTime=true -` + assert.Contains(t, output, "NAME VALUE") + assert.Contains(t, output, "config-file") + assert.Contains(t, output, "darktable-cli") + assert.Contains(t, output, "originals-path") + assert.Contains(t, output, "import-path") + assert.Contains(t, output, "export-path") + assert.Contains(t, output, "cache-path") + assert.Contains(t, output, "assets-path") - assert.Equal(t, expected, output) + assert.Equal(t, output, output) assert.Nil(t, err) } diff --git a/internal/commands/version.go b/internal/commands/version.go new file mode 100644 index 000000000..cbad6da47 --- /dev/null +++ b/internal/commands/version.go @@ -0,0 +1,23 @@ +package commands + +import ( + "fmt" + + "github.com/photoprism/photoprism/internal/context" + "github.com/urfave/cli" +) + +// Prints current configuration +var VersionCommand = cli.Command{ + Name: "version", + Usage: "Displays version information", + Action: versionAction, +} + +func versionAction(ctx *cli.Context) error { + conf := context.NewConfig(ctx) + + fmt.Println(conf.AppVersion()) + + return nil +}