File tree Expand file tree Collapse file tree 4 files changed +35
-8
lines changed
Expand file tree Collapse file tree 4 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 1+ package commands
2+
3+ import (
4+ "fmt"
5+ "os"
6+ "path/filepath"
7+ )
8+
9+ func validateDir (dir string ) {
10+ if dir == "" {
11+ cwd , err := os .Getwd ()
12+ handleError (err )
13+ dir = cwd
14+ }
15+
16+ abs , err := filepath .Abs (filepath .Join (dir , ".git" ))
17+ handleError (err )
18+
19+ if _ , err := os .Stat (abs ); os .IsNotExist (err ) {
20+ handleError (fmt .Errorf ("%s is not a git repository" , abs ))
21+ }
22+ }
Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ var rootCmd = &cobra.Command{
1313 Long : `tickgit is a tool for helping you manage tickets and todos in your codebase, as a part of your git history` ,
1414}
1515
16+ // TODO clean this up
17+ func handleError (err error ) {
18+ if err != nil {
19+ fmt .Println (err )
20+ os .Exit (1 )
21+ }
22+ }
23+
1624// Execute adds all child commands to the root command and sets flags appropriately.
1725func Execute () {
1826 if err := rootCmd .Execute (); err != nil {
Original file line number Diff line number Diff line change @@ -13,13 +13,6 @@ func init() {
1313 rootCmd .AddCommand (statusCmd )
1414}
1515
16- // TODO clean this up
17- func handleError (err error ) {
18- if err != nil {
19- panic (err )
20- }
21- }
22-
2316var statusCmd = & cobra.Command {
2417 Use : "status" ,
2518 Short : "Print a status report of the current directory" ,
@@ -35,6 +28,8 @@ var statusCmd = &cobra.Command{
3528 handleError (err )
3629 }
3730
31+ validateDir (dir )
32+
3833 r , err := git .PlainOpen (dir )
3934 handleError (err )
4035
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ func init() {
1717var todosCmd = & cobra.Command {
1818 Use : "todos" ,
1919 Short : "Print a report of current TODOs" ,
20- Long : `` ,
20+ Long : `Scans a given git repository looking for any code comments with TODOs. Displays a report of all the TODO items found. ` ,
2121 Args : cobra .MaximumNArgs (1 ),
2222 Run : func (cmd * cobra.Command , args []string ) {
2323 cwd , err := os .Getwd ()
@@ -29,6 +29,8 @@ var todosCmd = &cobra.Command{
2929 handleError (err )
3030 }
3131
32+ validateDir (dir )
33+
3234 r , err := git .PlainOpen (dir )
3335 handleError (err )
3436
You can’t perform that action at this time.
0 commit comments