1- using CommandLine ;
21using GVFS . Common ;
32using GVFS . Common . Git ;
43using GVFS . Common . Http ;
54using GVFS . Common . Prefetch ;
65using GVFS . Common . Tracing ;
76using System ;
7+ using System . CommandLine ;
88
99namespace FastFetch
1010{
11- [ Verb ( "fastfetch" , HelpText = "Fast-fetch a branch" ) ]
1211 public class FastFetchVerb
1312 {
1413 // Testing has shown that more than 16 download threads does not improve
@@ -19,131 +18,149 @@ public class FastFetchVerb
1918 private const int ExitFailure = 1 ;
2019 private const int ExitSuccess = 0 ;
2120
22- [ Option (
23- 'c' ,
24- "commit" ,
25- Required = false ,
26- HelpText = "Commit to fetch" ) ]
2721 public string Commit { get ; set ; }
2822
29- [ Option (
30- 'b' ,
31- "branch" ,
32- Required = false ,
33- HelpText = "Branch to fetch" ) ]
3423 public string Branch { get ; set ; }
3524
36- [ Option (
37- "cache-server-url" ,
38- Required = false ,
39- Default = "" ,
40- HelpText = "Defines the url of the cache server" ) ]
4125 public string CacheServerUrl { get ; set ; }
4226
43- [ Option (
44- "chunk-size" ,
45- Required = false ,
46- Default = 4000 ,
47- HelpText = "Sets the number of objects to be downloaded in a single pack" ) ]
4827 public int ChunkSize { get ; set ; }
4928
50- [ Option (
51- "checkout" ,
52- Required = false ,
53- Default = false ,
54- HelpText = "Checkout the target commit into the working directory after fetching" ) ]
5529 public bool Checkout { get ; set ; }
5630
57- [ Option (
58- "force-checkout" ,
59- Required = false ,
60- Default = false ,
61- HelpText = "Force FastFetch to checkout content as if the current repo had just been initialized." +
62- "This allows you to include more folders from the repo that were not originally checked out." +
63- "Can only be used with the --checkout option." ) ]
6431 public bool ForceCheckout { get ; set ; }
6532
66- [ Option (
67- "search-thread-count" ,
68- Required = false ,
69- Default = 0 ,
70- HelpText = "Sets the number of threads to use for finding missing blobs. (0 for number of logical cores)" ) ]
7133 public int SearchThreadCount { get ; set ; }
7234
73- [ Option (
74- "download-thread-count" ,
75- Required = false ,
76- Default = 0 ,
77- HelpText = "Sets the number of threads to use for downloading. (0 for number of logical cores)" ) ]
7835 public int DownloadThreadCount { get ; set ; }
7936
80- [ Option (
81- "index-thread-count" ,
82- Required = false ,
83- Default = 0 ,
84- HelpText = "Sets the number of threads to use for indexing. (0 for number of logical cores)" ) ]
8537 public int IndexThreadCount { get ; set ; }
8638
87- [ Option (
88- "checkout-thread-count" ,
89- Required = false ,
90- Default = 0 ,
91- HelpText = "Sets the number of threads to use for checkout. (0 for number of logical cores)" ) ]
9239 public int CheckoutThreadCount { get ; set ; }
9340
94- [ Option (
95- 'r' ,
96- "max-retries" ,
97- Required = false ,
98- Default = 10 ,
99- HelpText = "Sets the maximum number of attempts for downloading a pack" ) ]
100-
10141 public int MaxAttempts { get ; set ; }
10242
103- [ Option (
104- "git-path" ,
105- Default = "" ,
106- Required = false ,
107- HelpText = "Sets the path and filename for git.exe if it isn't expected to be on %PATH%." ) ]
10843 public string GitBinPath { get ; set ; }
109-
110- [ Option (
111- "folders" ,
112- Required = false ,
113- Default = "" ,
114- HelpText = "A semicolon-delimited list of folders to fetch" ) ]
44+
11545 public string FolderList { get ; set ; }
11646
117- [ Option (
118- "folders-list" ,
119- Required = false ,
120- Default = "" ,
121- HelpText = "A file containing line-delimited list of folders to fetch" ) ]
12247 public string FolderListFile { get ; set ; }
12348
124- [ Option (
125- "Allow-index-metadata-update-from-working-tree" ,
126- Required = false ,
127- Default = false ,
128- HelpText = "When specified, index metadata (file times and sizes) is updated from disk if not already in the index. " +
129- "This flag should only be used when the working tree is known to be in a good state. " +
130- "Do not use this flag if the working tree is not 100% known to be good as it would cause 'git status' to misreport." ) ]
13149 public bool AllowIndexMetadataUpdateFromWorkingTree { get ; set ; }
13250
133- [ Option (
134- "verbose" ,
135- Required = false ,
136- Default = false ,
137- HelpText = "Show all outputs on the console in addition to writing them to a log file" ) ]
13851 public bool Verbose { get ; set ; }
13952
140- [ Option (
141- "parent-activity-id" ,
142- Required = false ,
143- Default = "" ,
144- HelpText = "The GUID of the caller - used for telemetry purposes." ) ]
14553 public string ParentActivityId { get ; set ; }
14654
55+ public static RootCommand BuildRootCommand ( )
56+ {
57+ RootCommand rootCommand = new RootCommand ( "Fast-fetch a branch" ) ;
58+
59+ Option < string > commitOption = new Option < string > ( "--commit" , new [ ] { "-c" } ) { Description = "Commit to fetch" } ;
60+ rootCommand . Add ( commitOption ) ;
61+
62+ Option < string > branchOption = new Option < string > ( "--branch" , new [ ] { "-b" } ) { Description = "Branch to fetch" } ;
63+ rootCommand . Add ( branchOption ) ;
64+
65+ Option < string > cacheServerUrlOption = new Option < string > ( "--cache-server-url" )
66+ {
67+ Description = "Defines the url of the cache server" ,
68+ DefaultValueFactory = ( _ ) => ""
69+ } ;
70+ rootCommand . Add ( cacheServerUrlOption ) ;
71+
72+ Option < int > chunkSizeOption = new Option < int > ( "--chunk-size" )
73+ {
74+ Description = "Sets the number of objects to be downloaded in a single pack" ,
75+ DefaultValueFactory = ( _ ) => 4000
76+ } ;
77+ rootCommand . Add ( chunkSizeOption ) ;
78+
79+ Option < bool > checkoutOption = new Option < bool > ( "--checkout" ) { Description = "Checkout the target commit into the working directory after fetching" } ;
80+ rootCommand . Add ( checkoutOption ) ;
81+
82+ Option < bool > forceCheckoutOption = new Option < bool > ( "--force-checkout" ) { Description = "Force FastFetch to checkout content as if the current repo had just been initialized." } ;
83+ rootCommand . Add ( forceCheckoutOption ) ;
84+
85+ Option < int > searchThreadCountOption = new Option < int > ( "--search-thread-count" ) { Description = "Sets the number of threads to use for finding missing blobs. (0 for number of logical cores)" , DefaultValueFactory = ( _ ) => 0 } ;
86+ rootCommand . Add ( searchThreadCountOption ) ;
87+
88+ Option < int > downloadThreadCountOption = new Option < int > ( "--download-thread-count" ) { Description = "Sets the number of threads to use for downloading. (0 for number of logical cores)" , DefaultValueFactory = ( _ ) => 0 } ;
89+ rootCommand . Add ( downloadThreadCountOption ) ;
90+
91+ Option < int > indexThreadCountOption = new Option < int > ( "--index-thread-count" ) { Description = "Sets the number of threads to use for indexing. (0 for number of logical cores)" , DefaultValueFactory = ( _ ) => 0 } ;
92+ rootCommand . Add ( indexThreadCountOption ) ;
93+
94+ Option < int > checkoutThreadCountOption = new Option < int > ( "--checkout-thread-count" ) { Description = "Sets the number of threads to use for checkout. (0 for number of logical cores)" , DefaultValueFactory = ( _ ) => 0 } ;
95+ rootCommand . Add ( checkoutThreadCountOption ) ;
96+
97+ Option < int > maxRetriesOption = new Option < int > ( "--max-retries" , new [ ] { "-r" } )
98+ {
99+ Description = "Sets the maximum number of attempts for downloading a pack" ,
100+ DefaultValueFactory = ( _ ) => 10
101+ } ;
102+ rootCommand . Add ( maxRetriesOption ) ;
103+
104+ Option < string > gitPathOption = new Option < string > ( "--git-path" )
105+ {
106+ Description = "Sets the path and filename for git.exe if it isn't expected to be on %PATH%." ,
107+ DefaultValueFactory = ( _ ) => ""
108+ } ;
109+ rootCommand . Add ( gitPathOption ) ;
110+
111+ Option < string > foldersOption = new Option < string > ( "--folders" )
112+ {
113+ Description = "A semicolon-delimited list of folders to fetch" ,
114+ DefaultValueFactory = ( _ ) => ""
115+ } ;
116+ rootCommand . Add ( foldersOption ) ;
117+
118+ Option < string > foldersListOption = new Option < string > ( "--folders-list" )
119+ {
120+ Description = "A file containing line-delimited list of folders to fetch" ,
121+ DefaultValueFactory = ( _ ) => ""
122+ } ;
123+ rootCommand . Add ( foldersListOption ) ;
124+
125+ Option < bool > allowIndexMetadataOption = new Option < bool > ( "--Allow-index-metadata-update-from-working-tree" ) { Description = "When specified, index metadata is updated from disk if not already in the index." } ;
126+ rootCommand . Add ( allowIndexMetadataOption ) ;
127+
128+ Option < bool > verboseOption = new Option < bool > ( "--verbose" ) { Description = "Show all outputs on the console in addition to writing them to a log file" } ;
129+ rootCommand . Add ( verboseOption ) ;
130+
131+ Option < string > parentActivityIdOption = new Option < string > ( "--parent-activity-id" )
132+ {
133+ Description = "The GUID of the caller - used for telemetry purposes." ,
134+ DefaultValueFactory = ( _ ) => ""
135+ } ;
136+ rootCommand . Add ( parentActivityIdOption ) ;
137+
138+ rootCommand . SetAction ( ( ParseResult result ) =>
139+ {
140+ FastFetchVerb verb = new FastFetchVerb ( ) ;
141+ verb . Commit = result . GetValue ( commitOption ) ;
142+ verb . Branch = result . GetValue ( branchOption ) ;
143+ verb . CacheServerUrl = result . GetValue ( cacheServerUrlOption ) ?? "" ;
144+ verb . ChunkSize = result . GetValue ( chunkSizeOption ) ;
145+ verb . Checkout = result . GetValue ( checkoutOption ) ;
146+ verb . ForceCheckout = result . GetValue ( forceCheckoutOption ) ;
147+ verb . SearchThreadCount = result . GetValue ( searchThreadCountOption ) ;
148+ verb . DownloadThreadCount = result . GetValue ( downloadThreadCountOption ) ;
149+ verb . IndexThreadCount = result . GetValue ( indexThreadCountOption ) ;
150+ verb . CheckoutThreadCount = result . GetValue ( checkoutThreadCountOption ) ;
151+ verb . MaxAttempts = result . GetValue ( maxRetriesOption ) ;
152+ verb . GitBinPath = result . GetValue ( gitPathOption ) ?? "" ;
153+ verb . FolderList = result . GetValue ( foldersOption ) ?? "" ;
154+ verb . FolderListFile = result . GetValue ( foldersListOption ) ?? "" ;
155+ verb . AllowIndexMetadataUpdateFromWorkingTree = result . GetValue ( allowIndexMetadataOption ) ;
156+ verb . Verbose = result . GetValue ( verboseOption ) ;
157+ verb . ParentActivityId = result . GetValue ( parentActivityIdOption ) ?? "" ;
158+ verb . Execute ( ) ;
159+ } ) ;
160+
161+ return rootCommand ;
162+ }
163+
147164 public void Execute ( )
148165 {
149166 Environment . ExitCode = this . ExecuteWithExitCode ( ) ;
0 commit comments