-
Notifications
You must be signed in to change notification settings - Fork 91
/
Copy pathroot.go
58 lines (48 loc) · 1.35 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
"fmt"
"log"
"os"
"github.com/karthikkalarikal/Qube/models"
"github.com/karthikkalarikal/Qube/pkg/traversal"
"github.com/karthikkalarikal/Qube/pkg/util"
"github.com/spf13/cobra"
)
var (
rootCmd = &cobra.Command{
Use: "separation",
Short: "Connect your favorite celebrities.",
Long: `A cli application that let's you figure out the connection between actors by separation`,
Run: generate,
}
actor1 string
actor2 string
separation uint
)
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func init() {
rootCmd.PersistentFlags().StringVarP(&actor1, "actor1", "a", "", "name an actor/celeb")
rootCmd.PersistentFlags().StringVarP(&actor2, "actor2", "b", "", "name an actor/celeb")
// rootCmd.PersistentFlags().UintVarP(&separation, "separation", "s", 3, "separation between the actors/celebs")
}
func generate(_ *cobra.Command, args []string) {
config := models.Config{
Actor1: actor1,
Actor2: actor2,
// Separation: separation,
}
if err := util.Exists(config.Actor1); err != nil {
log.Printf("the name of the actor1: %s is incorrect %v", actor1, err)
os.Exit(1)
}
if err := util.Exists(config.Actor2); err != nil {
log.Printf("the name of the actor2: %s is incorrect %v", actor2, err)
os.Exit(1)
}
traversal.NewNode(config.Actor1, config.Actor2)
}