Skip to content

Commit

Permalink
Prepares args to use in command
Browse files Browse the repository at this point in the history
  • Loading branch information
chentex committed Oct 20, 2017
1 parent fbbe259 commit 5586f80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
14 changes: 2 additions & 12 deletions cmd/insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,13 @@ this command will, when executed correctly, insert the string in the file 'testf
$ go-sif insert -f testfile string to insert in the file
this command will, when executed correctly, insert the string at the end of file 'testfile' in line a new line`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
// TODO: Work your own magic here
fmt.Println("insert called")
return nil
},
}

func init() {
RootCmd.AddCommand(insertCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// insertCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// insertCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

}
8 changes: 4 additions & 4 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ import (
)

var (
cfgFile string
file string
line int
cfgFile, file, text string
line int
)

// RootCmd represents the base command when called without any subcommands
Expand All @@ -51,7 +50,8 @@ func Execute() {
func init() {
cobra.OnInitialize(initConfig)
RootCmd.PersistentFlags().StringVarP(&file, "file", "f", "", "The file where you want to insert the string")
RootCmd.PersistentFlags().IntVarP(&line, "line", "l", 0, "Line where the string is going to be inserted, if omited the string will be inserted in a new line at the end of the file")
RootCmd.PersistentFlags().IntVarP(&line, "line", "l", -1, "Line where the string is going to be inserted, if omited the string will be inserted \n in a new line at the end of the file. Count starts at 1.")
RootCmd.PersistentFlags().StringVarP(&text, "text", "t", "", "The to insert into file")
}

// initConfig reads in config file and ENV variables if set.
Expand Down

0 comments on commit 5586f80

Please sign in to comment.