@@ -10,14 +10,24 @@ import (
10
10
var rootCmd = & cobra.Command {
11
11
Use : "upreq" ,
12
12
Short : "upreq - a small CLI to help manage your requirements.txt file" ,
13
- Long : `upreq is a small CLI to help manage your requirements.txt file.` ,
14
- Args : cobra .ExactArgs (0 ),
13
+ Long : `upreq - a small CLI to help manage your requirements.txt file
14
+
15
+ For more information, visit: https://github.com/robswc/upreq
16
+
17
+ ` ,
18
+ Args : cobra .ExactArgs (0 ),
15
19
Run : func (cmd * cobra.Command , args []string ) {
16
20
21
+ // get the flags
22
+ file , _ := cmd .Flags ().GetString ("file" )
23
+ strip , _ := cmd .Flags ().GetBool ("strip" )
24
+ git , _ := cmd .Flags ().GetBool ("git" )
25
+
17
26
// grab current requirements
18
- var file = cmd .Flag ("file" ).Value .String ()
19
- var oldReqs = upreq .GetReqs (file )
20
- fmt .Printf ("Found (%[1]s) requirements in %[2]s\n " , fmt .Sprint (len (oldReqs )), file )
27
+ var oldReqs = upreq .GetReqs (file , strip )
28
+ if ! strip {
29
+ fmt .Printf ("Found (%[1]s) requirements in %[2]s\n " , fmt .Sprint (len (oldReqs )), file )
30
+ }
21
31
22
32
// wipe the file
23
33
upreq .WipeFile (file )
@@ -30,18 +40,25 @@ var rootCmd = &cobra.Command{
30
40
upreq .DisplayDiff (diff , cmd .Flag ("strip" ).Value .String ())
31
41
32
42
// write new requirements
33
- var writtenReqs = upreq .WriteReqs (file , newReqs )
34
- fmt .Printf ("Wrote (%[1]s) requirements to %[2]s\n " , fmt .Sprint (len (writtenReqs )), file )
43
+ var writtenReqs = upreq .WriteReqs (file , newReqs , strip )
44
+ if ! strip {
45
+ fmt .Printf ("Wrote (%[1]s) new requirements to %[2]s\n " , fmt .Sprint (len (writtenReqs )), file )
46
+ }
47
+
48
+ // add the file to git
49
+ if git {
50
+ upreq .GitAdd (file , strip )
51
+ }
35
52
36
53
},
37
54
}
38
55
39
56
func Execute () {
40
57
41
58
// add all the flags
42
- rootCmd .Flags ().StringP ("file" , "f" , "requirements.txt" , "Specify the requirements file to use " )
43
- rootCmd .Flags ().BoolP ("strip" , "s" , false , "Strips '+' and '-' from the output" )
44
- rootCmd .Flags ().BoolP ("git" , "g" , false , "Automatically add the file to git" )
59
+ rootCmd .Flags ().StringP ("file" , "f" , "requirements.txt" , "Specify the requirements file" )
60
+ rootCmd .Flags ().BoolP ("strip" , "s" , false , "Strips all feedback from the output (useful for piping) " )
61
+ rootCmd .Flags ().BoolP ("git" , "g" , false , "Automatically add the file to git, after writing " )
45
62
46
63
// run root command
47
64
if err := rootCmd .Execute (); err != nil {
0 commit comments