Browse Source

Add short cli flags -i and -v

Frédéric Guillot 6 months ago
parent
commit
3daef197e9
1 changed files with 40 additions and 16 deletions
  1. 40
    16
      cli/cli.go

+ 40
- 16
cli/cli.go View File

@@ -16,21 +16,45 @@ import (
16 16
 	"miniflux.app/version"
17 17
 )
18 18
 
19
+const (
20
+	flagInfoHelp = "Show application information"
21
+	flagVersionHelp = "Show application version"
22
+	flagMigrateHelp = "Run SQL migrations"
23
+	flagFlsuhSessionsHelp = "Flush all sessions (disconnect users)"
24
+	flagCreateAdminHelp = "Create admin user"
25
+	flagResetPasswordHelp = "Reset user password"
26
+	flagResetFeedErrorsHelp = "Clear all feed errors for all users"
27
+	flagDebugModeHelp = "Show debug logs"
28
+)
29
+
19 30
 // Parse parses command line arguments.
20 31
 func Parse() {
21
-	flagInfo := flag.Bool("info", false, "Show application information")
22
-	flagVersion := flag.Bool("version", false, "Show application version")
23
-	flagMigrate := flag.Bool("migrate", false, "Migrate database schema")
24
-	flagFlushSessions := flag.Bool("flush-sessions", false, "Flush all sessions (disconnect users)")
25
-	flagCreateAdmin := flag.Bool("create-admin", false, "Create admin user")
26
-	flagResetPassword := flag.Bool("reset-password", false, "Reset user password")
27
-	flagResetFeedErrors := flag.Bool("reset-feed-errors", false, "Clear all feed errors for all users")
28
-	flagDebugMode := flag.Bool("debug", false, "Enable debug mode (more verbose output)")
32
+	var (
33
+		flagInfo bool
34
+		flagVersion bool
35
+		flagMigrate bool
36
+		flagFlushSessions bool
37
+		flagCreateAdmin bool
38
+		flagResetPassword bool
39
+		flagResetFeedErrors bool
40
+		flagDebugMode bool
41
+	)
42
+
43
+	flag.BoolVar(&flagInfo, "info", false, flagInfoHelp)
44
+	flag.BoolVar(&flagInfo, "i", false, flagInfoHelp)
45
+	flag.BoolVar(&flagVersion, "version", false, flagVersionHelp)
46
+	flag.BoolVar(&flagVersion, "v", false, flagVersionHelp)
47
+	flag.BoolVar(&flagMigrate, "migrate", false, flagMigrateHelp)
48
+	flag.BoolVar(&flagFlushSessions, "flush-sessions", false, flagFlsuhSessionsHelp)
49
+	flag.BoolVar(&flagCreateAdmin, "create-admin", false, flagCreateAdminHelp)
50
+	flag.BoolVar(&flagResetPassword, "reset-password", false, flagResetPasswordHelp)
51
+	flag.BoolVar(&flagResetFeedErrors, "reset-feed-errors", false, flagResetFeedErrorsHelp)
52
+	flag.BoolVar(&flagDebugMode,"debug", false, flagDebugModeHelp)
29 53
 	flag.Parse()
30 54
 
31 55
 	cfg := config.NewConfig()
32 56
 
33
-	if *flagDebugMode || cfg.HasDebugMode() {
57
+	if flagDebugMode || cfg.HasDebugMode() {
34 58
 		logger.EnableDebug()
35 59
 	}
36 60
 
@@ -42,37 +66,37 @@ func Parse() {
42 66
 
43 67
 	store := storage.NewStorage(db)
44 68
 
45
-	if *flagInfo {
69
+	if flagInfo {
46 70
 		info()
47 71
 		return
48 72
 	}
49 73
 
50
-	if *flagVersion {
74
+	if flagVersion {
51 75
 		fmt.Println(version.Version)
52 76
 		return
53 77
 	}
54 78
 
55
-	if *flagMigrate {
79
+	if flagMigrate {
56 80
 		database.Migrate(db)
57 81
 		return
58 82
 	}
59 83
 
60
-	if *flagResetFeedErrors {
84
+	if flagResetFeedErrors {
61 85
 		store.ResetFeedErrors()
62 86
 		return
63 87
 	}
64 88
 
65
-	if *flagFlushSessions {
89
+	if flagFlushSessions {
66 90
 		flushSessions(store)
67 91
 		return
68 92
 	}
69 93
 
70
-	if *flagCreateAdmin {
94
+	if flagCreateAdmin {
71 95
 		createAdmin(store)
72 96
 		return
73 97
 	}
74 98
 
75
-	if *flagResetPassword {
99
+	if flagResetPassword {
76 100
 		resetPassword(store)
77 101
 		return
78 102
 	}

Loading…
Cancel
Save