Add short cli flags -i and -v

This commit is contained in:
Frédéric Guillot 2018-10-08 21:00:00 -07:00
parent 9606126196
commit 3daef197e9
1 changed files with 40 additions and 16 deletions

View File

@ -16,21 +16,45 @@ import (
"miniflux.app/version" "miniflux.app/version"
) )
const (
flagInfoHelp = "Show application information"
flagVersionHelp = "Show application version"
flagMigrateHelp = "Run SQL migrations"
flagFlsuhSessionsHelp = "Flush all sessions (disconnect users)"
flagCreateAdminHelp = "Create admin user"
flagResetPasswordHelp = "Reset user password"
flagResetFeedErrorsHelp = "Clear all feed errors for all users"
flagDebugModeHelp = "Show debug logs"
)
// Parse parses command line arguments. // Parse parses command line arguments.
func Parse() { func Parse() {
flagInfo := flag.Bool("info", false, "Show application information") var (
flagVersion := flag.Bool("version", false, "Show application version") flagInfo bool
flagMigrate := flag.Bool("migrate", false, "Migrate database schema") flagVersion bool
flagFlushSessions := flag.Bool("flush-sessions", false, "Flush all sessions (disconnect users)") flagMigrate bool
flagCreateAdmin := flag.Bool("create-admin", false, "Create admin user") flagFlushSessions bool
flagResetPassword := flag.Bool("reset-password", false, "Reset user password") flagCreateAdmin bool
flagResetFeedErrors := flag.Bool("reset-feed-errors", false, "Clear all feed errors for all users") flagResetPassword bool
flagDebugMode := flag.Bool("debug", false, "Enable debug mode (more verbose output)") flagResetFeedErrors bool
flagDebugMode bool
)
flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
flag.BoolVar(&flagInfo, "i", false, flagInfoHelp)
flag.BoolVar(&flagVersion, "version", false, flagVersionHelp)
flag.BoolVar(&flagVersion, "v", false, flagVersionHelp)
flag.BoolVar(&flagMigrate, "migrate", false, flagMigrateHelp)
flag.BoolVar(&flagFlushSessions, "flush-sessions", false, flagFlsuhSessionsHelp)
flag.BoolVar(&flagCreateAdmin, "create-admin", false, flagCreateAdminHelp)
flag.BoolVar(&flagResetPassword, "reset-password", false, flagResetPasswordHelp)
flag.BoolVar(&flagResetFeedErrors, "reset-feed-errors", false, flagResetFeedErrorsHelp)
flag.BoolVar(&flagDebugMode,"debug", false, flagDebugModeHelp)
flag.Parse() flag.Parse()
cfg := config.NewConfig() cfg := config.NewConfig()
if *flagDebugMode || cfg.HasDebugMode() { if flagDebugMode || cfg.HasDebugMode() {
logger.EnableDebug() logger.EnableDebug()
} }
@ -42,37 +66,37 @@ func Parse() {
store := storage.NewStorage(db) store := storage.NewStorage(db)
if *flagInfo { if flagInfo {
info() info()
return return
} }
if *flagVersion { if flagVersion {
fmt.Println(version.Version) fmt.Println(version.Version)
return return
} }
if *flagMigrate { if flagMigrate {
database.Migrate(db) database.Migrate(db)
return return
} }
if *flagResetFeedErrors { if flagResetFeedErrors {
store.ResetFeedErrors() store.ResetFeedErrors()
return return
} }
if *flagFlushSessions { if flagFlushSessions {
flushSessions(store) flushSessions(store)
return return
} }
if *flagCreateAdmin { if flagCreateAdmin {
createAdmin(store) createAdmin(store)
return return
} }
if *flagResetPassword { if flagResetPassword {
resetPassword(store) resetPassword(store)
return return
} }