@@ -8,14 +8,20 @@ import (
88 "os/exec"
99 "strings"
1010
11+ "github.com/sirupsen/logrus"
12+
13+ "github.com/liamg/gitjacker/internal/app/version"
1114 "github.com/liamg/gitjacker/internal/pkg/gitjacker"
15+ "github.com/liamg/tml"
1216 "github.com/spf13/cobra"
1317)
1418
1519var outputDir string
20+ var verbose bool
1621
1722func main () {
1823
24+ rootCmd .Flags ().BoolVarP (& verbose , "verbose" , "v" , verbose , "Enable verbose logging" )
1925 rootCmd .Flags ().StringVarP (& outputDir , "output-dir" , "o" , outputDir , "Directory to output retrieved git repository - defaults to a temporary directory" )
2026
2127 if err := rootCmd .Execute (); err != nil {
@@ -32,6 +38,15 @@ More information at https://github.com/liamg/gitjacker`,
3238 Args : cobra .ExactArgs (1 ),
3339 RunE : func (cmd * cobra.Command , args []string ) error {
3440
41+ _ = tml .Printf (`<red>
42+ ██████ ██ ████████ ██ █████ ██████ ██ ██ ███████ ██████
43+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
44+ ██ ███ ██ ██ ██ ███████ ██ █████ █████ ██████
45+ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
46+ ██████ ██ ██ █████ ██ ██ ██████ ██ ██ ███████ ██ ██
47+ https://github.com/liamg/gitjacker %9s
48+ ` , version .Version )
49+
3550 rawURL := args [0 ]
3651 rawURL = strings .TrimSuffix (rawURL , "/.git/" )
3752 rawURL = strings .TrimSuffix (rawURL , "/.git" )
@@ -56,15 +71,74 @@ More information at https://github.com/liamg/gitjacker`,
5671 if err != nil {
5772 return fmt .Errorf ("failed to start git: %w - please check it is installed" , err )
5873 }
74+ versionParts := strings .Split (string (versionData ), " " )
75+ version := strings .TrimSpace (versionParts [len (versionParts )- 1 ])
76+
77+ if verbose {
78+ logrus .SetLevel (logrus .DebugLevel )
79+ }
5980
60- version := strings .Split (string (versionData ), " " )
61- _ = version // TODO output this
81+ tml .Printf (`
82+ Target: <yellow>%s</yellow>
83+ Local Git: %s
84+ Output Dir: %s
85+ ` , u .String (), version , outputDir )
6286
63- if err := gitjacker .New (u , outputDir ).Run (); err != nil {
87+ if ! verbose {
88+ _ = tml .Printf ("\n <yellow>Gitjacking in progress..." )
89+ }
90+
91+ summary , err := gitjacker .New (u , outputDir ).Run ()
92+ if err != nil {
93+ if ! verbose {
94+ fmt .Printf ("\x1b [2K\r " )
95+ }
6496 return err
6597 }
6698
67- fmt .Printf ("Output directory: %s\n " , outputDir )
99+ if ! verbose {
100+ _ = tml .Printf ("\x1b [2K\r <yellow>Operation complete.\n " )
101+ }
102+
103+ status := "FAILED"
104+ switch summary .Status {
105+ case gitjacker .StatusPartialSuccess :
106+ status = tml .Sprintf ("<yellow>Partial Success" )
107+ case gitjacker .StatusSuccess :
108+ status = tml .Sprintf ("<green>Success" )
109+ }
110+
111+ var remoteStr string
112+ for _ , remote := range summary .Config .Remotes {
113+ remoteStr = fmt .Sprintf ("%s\n - %s: %s" , remoteStr , remote .Name , remote .URL )
114+ }
115+
116+ var branchStr string
117+ for _ , branch := range summary .Config .Branches {
118+ branchStr = fmt .Sprintf ("%s\n - %s (%s)" , branchStr , branch .Name , branch .Remote )
119+ }
120+
121+ _ = tml .Printf (`
122+ Status: %s
123+ Retrieved Objects: <green>%d</green>
124+ Missing Objects: <red>%d</red>
125+ Pack Data Listed: %t
126+ Repository: %s
127+ Remotes: %s
128+ Branches: %s
129+
130+ You can find the retrieved repository data in <blue>%s</blue>
131+
132+ ` ,
133+ status ,
134+ len (summary .FoundObjects ),
135+ len (summary .MissingObjects ),
136+ summary .PackInformationAvailable ,
137+ summary .Config .RepositoryName ,
138+ remoteStr ,
139+ branchStr ,
140+ summary .OutputDirectory ,
141+ )
68142
69143 return nil
70144 },
0 commit comments