github.com/mmrath/gobase@v0.0.1/apps/db_migration/cmd/root.go (about)

     1  package cmd
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/spf13/cobra"
     8  	"github.com/mmrath/gobase/apps/db_migration/app"
     9  )
    10  
    11  // rootCmd represents the base command when called without any subcommands
    12  var rootCmd = &cobra.Command{
    13  	Use:   "fina",
    14  	Short: "Upgrades DB",
    15  	Long:  `Upgrades DB to the latest version by applying all the migrations incrementally`,
    16  	Run: func(cmd *cobra.Command, args []string) {
    17  		err := app.Upgrade()
    18  		if err != nil {
    19  			fmt.Printf("Error in upgrade step: %s", err)
    20  		}
    21  	},
    22  }
    23  
    24  // Execute adds all child commands to the root command and sets flags appropriately.
    25  // This is called by main.main(). It only needs to happen once to the rootCmd.
    26  func Execute() {
    27  	if err := rootCmd.Execute(); err != nil {
    28  		fmt.Println(err)
    29  		os.Exit(1)
    30  	}
    31  }