github.com/jalalahmad/iplan@v0.0.1-alpha.7/internal/command/commands.go (about)

     1  package command
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/jalalahmad/iplan/internal/app/iplan"
     6  	"github.com/jalalahmad/iplan/internal/configs"
     7  	"os"
     8  
     9  	"github.com/spf13/cobra"
    10  )
    11  
    12  var rootCmd = &cobra.Command{
    13  	Use:   "iplan",
    14  	Short: "iplan is utility to manage user stories inn plain text",
    15  	Long: `A Fast and Flexible text based user story management utility
    16  built in Go.`,
    17  	Run: func(cmd *cobra.Command, args []string) {
    18  		// Do Stuff Here
    19  	},
    20  }
    21  
    22  var initCmd = &cobra.Command{
    23  	Use:   "init",
    24  	Short: "initialize directory for iplan use",
    25  	Long:  `Sets up config file with sample story and make directory versioned.`,
    26  	RunE: func(cmd *cobra.Command, args []string) error {
    27  		cwd, err := os.Getwd()
    28  		if err != nil {
    29  			return err
    30  		}
    31  
    32  		r, err := iplan.InitEmptyGit(cwd)
    33  		if err != nil {
    34  			return err
    35  		}
    36  
    37  		err = configs.CreateInitialFiles(cwd)
    38  		if err != nil {
    39  			return err
    40  		}
    41  
    42  		_, err = iplan.AddAndCommitFile(r, "gitignore")
    43  		return err
    44  	},
    45  }
    46  
    47  func init() {
    48  	cobra.OnInitialize(configs.InitConfig)
    49  	rootCmd.PersistentFlags().StringVar(&configs.CfgFile, "config", "", "config file (default is ./.iplan.yaml)")
    50  	rootCmd.AddCommand(initCmd)
    51  }
    52  
    53  func Execute() {
    54  	if err := rootCmd.Execute(); err != nil {
    55  		fmt.Fprintln(os.Stderr, err)
    56  		os.Exit(1)
    57  	}
    58  }