Add version command, see #50

This commit is contained in:
Michael Mayer 2018-12-21 04:32:17 +01:00
parent 5345ad37a2
commit 9e887be2d6
4 changed files with 56 additions and 16 deletions

View file

@ -20,6 +20,7 @@ func main() {
app.Commands = []cli.Command{
commands.ConfigCommand,
commands.VersionCommand,
commands.StartCommand,
commands.MigrateCommand,
commands.ImportCommand,

View file

@ -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
}

View file

@ -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)
}

View file

@ -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
}