Skip to content

Commit 6d0d75f

Browse files
authored
[cli] add comments (hasura#4)
Especially for godoc
1 parent 47c73f7 commit 6d0d75f

15 files changed

Lines changed: 55 additions & 51 deletions

cli/commands/console.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func NewConsoleCmd(ec *cli.ExecutionContext) *cobra.Command {
4040
return ec.Validate()
4141
},
4242
RunE: func(cmd *cobra.Command, args []string) error {
43-
return opts.Run()
43+
return opts.run()
4444
},
4545
}
4646
f := consoleCmd.Flags()
@@ -71,7 +71,7 @@ type consoleOptions struct {
7171
WG *sync.WaitGroup
7272
}
7373

74-
func (o *consoleOptions) Run() error {
74+
func (o *consoleOptions) run() error {
7575
log := o.EC.Logger
7676
// Switch to "release" mode in production.
7777
gin.SetMode(gin.ReleaseMode)

cli/commands/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func NewInitCmd(ec *cli.ExecutionContext) *cobra.Command {
4141
return ec.Prepare()
4242
},
4343
RunE: func(cmd *cobra.Command, args []string) error {
44-
return opts.Run()
44+
return opts.run()
4545
},
4646
}
4747

@@ -60,7 +60,7 @@ type initOptions struct {
6060
InitDir string
6161
}
6262

63-
func (o *initOptions) Run() error {
63+
func (o *initOptions) run() error {
6464
if o.EC.ExecutionDirectory == "" {
6565
o.EC.ExecutionDirectory = o.InitDir
6666
}

cli/commands/metadata.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func NewMetadataCmd(ec *cli.ExecutionContext) *cobra.Command {
1818
},
1919
}
2020
metadataCmd.AddCommand(
21-
NewMetadataExportCmd(ec),
22-
NewMetadataResetCmd(ec),
23-
NewMetadataApplyCmd(ec),
21+
newMetadataExportCmd(ec),
22+
newMetadataResetCmd(ec),
23+
newMetadataApplyCmd(ec),
2424
)
2525
f := metadataCmd.PersistentFlags()
2626
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")

cli/commands/metadata_apply.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
func NewMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
12+
func newMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
1313
opts := &metadataApplyOptions{
1414
EC: ec,
1515
actionType: "apply",
@@ -22,7 +22,7 @@ func NewMetadataApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
2222
hasura metadata apply`,
2323
SilenceUsage: true,
2424
RunE: func(cmd *cobra.Command, args []string) error {
25-
return opts.Run()
25+
return opts.run()
2626
},
2727
}
2828

@@ -35,7 +35,7 @@ type metadataApplyOptions struct {
3535
actionType string
3636
}
3737

38-
func (o *metadataApplyOptions) Run() error {
38+
func (o *metadataApplyOptions) run() error {
3939
dbURL, err := url.Parse(o.EC.Config.Endpoint)
4040
if err != nil {
4141
return errors.Wrap(err, "error parsing Endpoint")

cli/commands/metadata_export.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
func NewMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
12+
func newMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
1313
opts := &metadataExportOptions{
1414
EC: ec,
1515
actionType: "export",
@@ -22,7 +22,7 @@ func NewMetadataExportCmd(ec *cli.ExecutionContext) *cobra.Command {
2222
hasura metadata export`,
2323
SilenceUsage: true,
2424
RunE: func(cmd *cobra.Command, args []string) error {
25-
return opts.Run()
25+
return opts.run()
2626
},
2727
}
2828

@@ -35,7 +35,7 @@ type metadataExportOptions struct {
3535
actionType string
3636
}
3737

38-
func (o *metadataExportOptions) Run() error {
38+
func (o *metadataExportOptions) run() error {
3939
dbURL, err := url.Parse(o.EC.Config.Endpoint)
4040
if err != nil {
4141
return errors.Wrap(err, "error parsing Endpoint")

cli/commands/metadata_reset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
func NewMetadataResetCmd(ec *cli.ExecutionContext) *cobra.Command {
12+
func newMetadataResetCmd(ec *cli.ExecutionContext) *cobra.Command {
1313
opts := &metadataResetOptions{
1414
EC: ec,
1515
actionType: "reset",
@@ -22,7 +22,7 @@ func NewMetadataResetCmd(ec *cli.ExecutionContext) *cobra.Command {
2222
hasura metadata reset`,
2323
SilenceUsage: true,
2424
RunE: func(cmd *cobra.Command, args []string) error {
25-
return opts.Run()
25+
return opts.run()
2626
},
2727
}
2828

@@ -35,7 +35,7 @@ type metadataResetOptions struct {
3535
actionType string
3636
}
3737

38-
func (o *metadataResetOptions) Run() error {
38+
func (o *metadataResetOptions) run() error {
3939
dbURL, err := url.Parse(o.EC.Config.Endpoint)
4040
if err != nil {
4141
return errors.Wrap(err, "error parsing Endpoint")

cli/commands/migrate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ func NewMigrateCmd(ec *cli.ExecutionContext) *cobra.Command {
2020
},
2121
}
2222
migrateCmd.AddCommand(
23-
NewMigrateApplyCmd(ec),
24-
NewMigrateStatusCmd(ec),
25-
NewMigrateCreateCmd(ec),
23+
newMigrateApplyCmd(ec),
24+
newMigrateStatusCmd(ec),
25+
newMigrateCreateCmd(ec),
2626
)
2727
f := migrateCmd.PersistentFlags()
2828
f.String("endpoint", "", "http(s) endpoint for Hasura GraphQL Engine")

cli/commands/migrate_apply.go

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,7 @@ import (
1111
"github.com/spf13/cobra"
1212
)
1313

14-
var (
15-
UP_MIGRATION_HELP = "apply all or N up migration steps"
16-
DOWN_MIGRATION_HELP = "apply all or N down migration steps"
17-
VERSION_MIGRATION_HELP = "migrate the database to a specific version specified by the timestamp"
18-
)
19-
20-
const FLAG_NOT_SET = ""
21-
22-
func NewMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
14+
func newMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
2315
opts := &migrateApplyOptions{
2416
EC: ec,
2517
}
@@ -28,15 +20,15 @@ func NewMigrateApplyCmd(ec *cli.ExecutionContext) *cobra.Command {
2820
Short: "Apply migrations on the database",
2921
SilenceUsage: true,
3022
RunE: func(cmd *cobra.Command, args []string) error {
31-
return opts.Run()
23+
return opts.run()
3224
},
3325
}
3426
f := migrateApplyCmd.Flags()
3527

36-
f.StringVar(&opts.upMigration, "up", FLAG_NOT_SET, UP_MIGRATION_HELP)
37-
f.StringVar(&opts.downMigration, "down", FLAG_NOT_SET, DOWN_MIGRATION_HELP)
38-
f.StringVar(&opts.versionMigration, "version", FLAG_NOT_SET, VERSION_MIGRATION_HELP)
39-
f.StringVar(&opts.typeMigration, "type", FLAG_NOT_SET, VERSION_MIGRATION_HELP)
28+
f.StringVar(&opts.upMigration, "up", "", "apply all or N up migration steps")
29+
f.StringVar(&opts.downMigration, "down", "", "apply all or N down migration steps")
30+
f.StringVar(&opts.versionMigration, "version", "", "migrate the database to a specific version")
31+
f.StringVar(&opts.migrationType, "type", "up", "type of migration (up, down) to be used with version flag")
4032
return migrateApplyCmd
4133
}
4234

@@ -46,11 +38,11 @@ type migrateApplyOptions struct {
4638
upMigration string
4739
downMigration string
4840
versionMigration string
49-
typeMigration string
41+
migrationType string
5042
}
5143

52-
func (o *migrateApplyOptions) Run() error {
53-
migrationType, step, err := getMigrationTypeAndStep(o.upMigration, o.downMigration, o.versionMigration, o.typeMigration)
44+
func (o *migrateApplyOptions) run() error {
45+
migrationType, step, err := getMigrationTypeAndStep(o.upMigration, o.downMigration, o.versionMigration, o.migrationType)
5446
if err != nil {
5547
return errors.Wrap(err, "error validating flags")
5648
}
@@ -75,24 +67,25 @@ func (o *migrateApplyOptions) Run() error {
7567
return nil
7668
}
7769

78-
//Only one flag out of up,down and goto can be set at a time. This function checks whether that is the case and returns an error is not
79-
func getMigrationTypeAndStep(upMigration, downMigration, versionMigration, typeMigration string) (string, int64, error) {
70+
// Only one flag out of up, down and version can be set at a time. This function
71+
// checks whether that is the case and returns an error is not
72+
func getMigrationTypeAndStep(upMigration, downMigration, versionMigration, migrationType string) (string, int64, error) {
8073
var flagCount = 0
8174
var stepString = "all"
8275
var migrationName = "up"
83-
if upMigration != FLAG_NOT_SET {
76+
if upMigration != "" {
8477
stepString = upMigration
8578
flagCount++
8679
}
87-
if downMigration != FLAG_NOT_SET {
80+
if downMigration != "" {
8881
migrationName = "down"
8982
stepString = downMigration
9083
flagCount++
9184
}
92-
if versionMigration != FLAG_NOT_SET {
85+
if versionMigration != "" {
9386
migrationName = "version"
9487
stepString = versionMigration
95-
if typeMigration != FLAG_NOT_SET {
88+
if migrationType == "down" {
9689
stepString = "-" + stepString
9790
}
9891
flagCount++

cli/commands/migrate_create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
func NewMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command {
12+
func newMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command {
1313
opts := &migrateCreateOptions{
1414
EC: ec,
1515
}
@@ -22,7 +22,7 @@ func NewMigrateCreateCmd(ec *cli.ExecutionContext) *cobra.Command {
2222
Args: cobra.ExactArgs(1),
2323
RunE: func(cmd *cobra.Command, args []string) error {
2424
opts.name = args[0]
25-
return opts.Run()
25+
return opts.run()
2626
},
2727
}
2828

@@ -35,7 +35,7 @@ type migrateCreateOptions struct {
3535
name string
3636
}
3737

38-
func (o *migrateCreateOptions) Run() error {
38+
func (o *migrateCreateOptions) run() error {
3939
timestamp := getTime()
4040
err := mig.CreateCmd(o.EC.MigrationDir, timestamp, o.name)
4141
if err != nil {

cli/commands/migrate_status.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
func NewMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
12+
func newMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
1313
opts := &migrateStatusOptions{
1414
EC: ec,
1515
}
@@ -18,7 +18,7 @@ func NewMigrateStatusCmd(ec *cli.ExecutionContext) *cobra.Command {
1818
Short: "Display current status of migrations on a database",
1919
SilenceUsage: true,
2020
RunE: func(cmd *cobra.Command, args []string) error {
21-
return opts.Run()
21+
return opts.run()
2222
},
2323
}
2424

@@ -29,7 +29,7 @@ type migrateStatusOptions struct {
2929
EC *cli.ExecutionContext
3030
}
3131

32-
func (o *migrateStatusOptions) Run() error {
32+
func (o *migrateStatusOptions) run() error {
3333
dbURL, err := url.Parse(o.EC.Config.Endpoint)
3434
if err != nil {
3535
return errors.Wrap(err, "error parsing Endpoint")

0 commit comments

Comments
 (0)