forked from goffee/goffee
initial commits 1
This commit is contained in:
parent
61645c1459
commit
c97afa7564
19 changed files with 1612 additions and 142 deletions
61
cmd/generate-eventjob.go
Normal file
61
cmd/generate-eventjob.go
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
// Copyright © Harran Ali <harran.m@gmail.com>. All rights reserved.
|
||||
// Use of this source code is governed by MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var GenerateEventJobCmd = &cobra.Command{
|
||||
Use: "gen:eventjob [JobName]",
|
||||
Short: "Create an event job",
|
||||
Long: `Helps you generate a boilderplate code for event jobs
|
||||
example:
|
||||
goffee gen:eventjob EventJobName
|
||||
|
||||
`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
pwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
eventJobName := args[0]
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
jfn := camelCaseToSnake(eventJobName, "-") + ".go"
|
||||
ffnp := filepath.Join(pwd, "events/eventjobs", jfn)
|
||||
jfs, err := os.Stat(ffnp)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
fmt.Printf("problem creating the file: %v\n", ffnp)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if jfs != nil {
|
||||
fmt.Printf("file \"%v\" already exist\n", jfn)
|
||||
os.Exit(1)
|
||||
}
|
||||
jobFile, err := os.Create(ffnp)
|
||||
if err != err {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
jobFile.WriteString(prepareJobContent(eventJobName))
|
||||
jobFile.Close()
|
||||
fmt.Println("event job generated successfully")
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(GenerateEventJobCmd)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue