MCPcopy Create free account
hub / github.com/dlvhdr/diffnav / init

Function init

cmd/root.go:82–232  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80}
81
82func init() {
83 rootCmd.Flags().BoolP("side-by-side", "s", false, "Force side-by-side diff view")
84
85 rootCmd.Flags().BoolP("unified", "u", false, "Force unified diff view")
86
87 rootCmd.Flags().
88 BoolP("watch", "w", false, "Watch mode: periodically re-run a diff command and refresh")
89 rootCmd.Flags().String("watch-cmd", "git diff", "Command to run in watch mode")
90 rootCmd.Flags().Duration("watch-interval", 2*time.Second, "Interval between watch refreshes")
91
92 rootCmd.SetVersionTemplate("\n" + logo + "\n" + `{{printf "version %s\n" .Version}}`)
93
94 rootCmd.Run = func(cmd *cobra.Command, args []string) {
95 // Parse CLI flags
96 sideBySideFlag, err := cmd.Flags().GetBool("side-by-side")
97 if err != nil {
98 log.Fatal("Cannot parse the side-by-side flag", err)
99 }
100 unifiedFlag, err := cmd.Flags().GetBool("unified")
101 if err != nil {
102 log.Fatal("Cannot parse the unified flag", err)
103 }
104
105 helpFlag, err := cmd.Flags().GetBool("help")
106 if err != nil {
107 log.Fatal("Cannot parse the help flag", err)
108 }
109
110 watchFlag, err := cmd.Flags().GetBool("watch")
111 if err != nil {
112 log.Fatal("Cannot parse the watch flag", err)
113 }
114 watchCmd, err := cmd.Flags().GetString("watch-cmd")
115 if err != nil {
116 log.Fatal("Cannot parse the watch-cmd flag", err)
117 }
118 watchInterval, err := cmd.Flags().GetDuration("watch-interval")
119 if err != nil {
120 log.Fatal("Cannot parse the watch-interval flag", err)
121 }
122 if cmd.Flags().Changed("watch-cmd") {
123 watchFlag = true
124 }
125
126 zone.NewGlobal()
127
128 if os.Getenv("DEBUG") == "true" {
129 var fileErr error
130 logFile, fileErr := os.OpenFile("debug.log",
131 os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o666)
132 if fileErr != nil {
133 fmt.Println("Error opening debug.log:", fileErr)
134 os.Exit(1)
135 }
136 defer func() {
137 if err := logFile.Close(); err != nil {
138 log.Fatal("failed closing log file", "err", err)
139 }

Callers

nothing calls this directly

Calls 4

RunCmdFunction · 0.92
LoadFunction · 0.92
NewFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected