11using DescribeCompiler ;
22using System ;
3- using System . Collections . Generic ;
43using System . IO ;
5- using System . Linq ;
6- using System . Text ;
7- using System . Threading . Tasks ;
84
95namespace DescribeCompilerCLI
106{
@@ -90,7 +86,7 @@ internal static bool readInputFileArgument(string arg, int argindex)
9086 }
9187 catch ( Exception ex )
9288 {
93- Messages . printArgumentError ( arg , argindex , "is not a valid file or folder " ) ;
89+ Messages . printArgumentError ( arg , argindex , "is not a valid file" ) ;
9490 return false ;
9591 }
9692 }
@@ -120,7 +116,7 @@ internal static bool readInputFolderArgument(string arg, int argindex)
120116 }
121117 catch ( Exception ex )
122118 {
123- Messages . printArgumentError ( arg , argindex , "is not a valid file or folder" ) ;
119+ Messages . printArgumentError ( arg , argindex , "is not a valid folder" ) ;
124120 return false ;
125121 }
126122 }
@@ -131,7 +127,7 @@ internal static bool readInputFolderArgument(string arg, int argindex)
131127 /// <param name="arg">The argument raw text</param>
132128 /// <param name="argindex">The index of the argument (for logging purposes)</param>
133129 /// <returns>True if successful</returns>
134- internal static bool readOutputArgument ( string arg , int argindex )
130+ internal static bool readOutputArgument ( string arg , int argindex , bool isDir )
135131 {
136132 try
137133 {
@@ -155,8 +151,7 @@ internal static bool readOutputArgument(string arg, int argindex)
155151 DirectoryInfo di = Directory . GetParent ( arg ) ;
156152 if ( di . Exists )
157153 {
158- if ( Path . GetFileName ( arg ) == string . Empty ) Datnik . isOutputDir = true ;
159- else Datnik . isOutputDir = false ;
154+ Datnik . isOutputDir = isDir ;
160155 Datnik . output = arg ;
161156 return true ;
162157 }
@@ -204,17 +199,9 @@ internal static bool readOutputFileArgument(string arg, int argindex)
204199 DirectoryInfo di = Directory . GetParent ( arg ) ;
205200 if ( di . Exists )
206201 {
207- if ( Path . GetFileName ( arg ) == string . Empty )
208- {
209- Messages . printArgumentError ( arg , argindex , "is a folder. File is required" ) ;
210- return false ;
211- }
212- else
213- {
214- Datnik . output = arg ;
215- Datnik . isOutputDir = false ;
216- return true ;
217- }
202+ Datnik . output = arg ;
203+ Datnik . isOutputDir = false ;
204+ return true ;
218205 }
219206 else
220207 {
@@ -241,13 +228,13 @@ internal static bool readOutputFolderArgument(string arg, int argindex)
241228 {
242229 try
243230 {
244- //existing file - ok
231+ //existing file - not ok
245232 if ( File . Exists ( arg ) )
246233 {
247234 Messages . printArgumentError ( arg , argindex , "is a file. Folder is required" ) ;
248235 return false ;
249236 }
250- //existing dir - not ok
237+ //existing dir - ok
251238 else if ( Directory . Exists ( arg ) )
252239 {
253240 Datnik . output = arg ;
@@ -260,17 +247,9 @@ internal static bool readOutputFolderArgument(string arg, int argindex)
260247 DirectoryInfo di = Directory . GetParent ( arg ) ;
261248 if ( di . Exists )
262249 {
263- if ( Path . GetFileName ( arg ) == string . Empty )
264- {
265- Datnik . output = arg ;
266- Datnik . isOutputDir = true ;
267- return true ;
268- }
269- else
270- {
271- Messages . printArgumentError ( arg , argindex , "is a file. Folder is required" ) ;
272- return false ;
273- }
250+ Datnik . output = arg ;
251+ Datnik . isOutputDir = true ;
252+ return true ;
274253 }
275254 else
276255 {
@@ -306,9 +285,8 @@ internal static bool readDsonlyArgument(string arg, int argindex)
306285 Messages . printArgumentError ( arg , argindex , "" ) ;
307286 return false ;
308287 }
309- else if ( val == "true" || val == "l" ) Datnik . verbosity = LogVerbosity . Low ;
310- else if ( val == "medium" || val == "m" ) Datnik . verbosity = LogVerbosity . Medium ;
311- else if ( val == "high" || val == "h" ) Datnik . verbosity = LogVerbosity . High ;
288+ else if ( val == "true" ) Datnik . dsOnly = true ;
289+ else if ( val == "false" ) Datnik . dsOnly = false ;
312290 else
313291 {
314292 Messages . printArgumentError ( arg ,
@@ -453,8 +431,7 @@ internal static bool readTemplateArgument(string arg, int argindex)
453431 }
454432 else
455433 {
456- FileAttributes attr = File . GetAttributes ( val ) ;
457- if ( ( attr & FileAttributes . Directory ) == FileAttributes . Directory )
434+ if ( Directory . Exists ( val ) )
458435 {
459436 Datnik . templateName = new DirectoryInfo ( val ) . Name ;
460437 Datnik . templatePath = val ;
@@ -464,7 +441,6 @@ internal static bool readTemplateArgument(string arg, int argindex)
464441 else
465442 {
466443 string [ ] names = ResourceUtil . extractResourceNames ( ) ;
467- bool flag = false ;
468444 foreach ( string s in names )
469445 {
470446 if ( s . StartsWith ( "DescribeCompiler.Templates." + val + "." ) )
@@ -499,27 +475,37 @@ internal static bool readLogfileArgument(string arg, int argindex)
499475 {
500476 try
501477 {
478+ string val = arg . Substring ( arg . IndexOf ( "=" ) + 1 ) ;
479+ if ( string . IsNullOrEmpty ( val ) || string . IsNullOrWhiteSpace ( val ) )
480+ {
481+ Messages . printArgumentError ( arg , argindex , "" ) ;
482+ return false ;
483+ }
484+ //there is a bug in visual studio I think where if your path
485+ //in the command line parameter is in parentheses and ends with
486+ //a backslash, it is treated as an escaped backslash
487+
502488 //existing file - ok
503- if ( File . Exists ( arg ) )
489+ if ( File . Exists ( val ) )
504490 {
505- Datnik . logFilePath = arg ;
491+ Datnik . logFilePath = val ;
506492 Datnik . logToFile = true ;
507493 return true ;
508494 }
509495 //existing dir - ok
510- else if ( Directory . Exists ( arg ) )
496+ else if ( Directory . Exists ( val ) )
511497 {
512- Datnik . logFilePath = arg ;
498+ Datnik . logFilePath = Path . Combine ( val , "lastlog.txt" ) ;
513499 Datnik . logToFile = true ;
514500 return true ;
515501 }
516502 else
517503 {
518504 // notexisting file or dir - we want parent dir to exist
519- DirectoryInfo di = Directory . GetParent ( arg ) ;
505+ DirectoryInfo di = Directory . GetParent ( val ) ;
520506 if ( di . Exists )
521507 {
522- Datnik . logFilePath = arg ;
508+ Datnik . logFilePath = val ;
523509 Datnik . logToFile = true ;
524510 return true ;
525511 }
@@ -558,9 +544,10 @@ internal static bool readArtifactsArgument(string arg, int argindex)
558544 Messages . printArgumentError ( arg , argindex , "" ) ;
559545 return false ;
560546 }
561- else if ( val == "low" || val == "l" ) Datnik . verbosity = LogVerbosity . Low ;
562- else if ( val == "medium" || val == "m" ) Datnik . verbosity = LogVerbosity . Medium ;
563- else if ( val == "high" || val == "h" ) Datnik . verbosity = LogVerbosity . High ;
547+ else if ( val == "m" || val == "makeonly" ) Datnik . artifactMode = DescribeCompiler . Compiler . ArtifactMode . MakeOnly ;
548+ else if ( val == "t" || val == "takeonly" ) Datnik . artifactMode = DescribeCompiler . Compiler . ArtifactMode . TakeOnly ;
549+ else if ( val == "u" || val == "use" ) Datnik . artifactMode = DescribeCompiler . Compiler . ArtifactMode . Use ;
550+ else if ( val == "n" || val == "no" ) Datnik . artifactMode = DescribeCompiler . Compiler . ArtifactMode . No ;
564551 else
565552 {
566553 Messages . printArgumentError ( arg ,
@@ -588,10 +575,17 @@ internal static bool readArtifactsPathArgument(string arg, int argindex)
588575 {
589576 try
590577 {
578+ string val = arg . Substring ( arg . IndexOf ( "=" ) + 1 ) ;
579+ if ( string . IsNullOrEmpty ( val ) || string . IsNullOrWhiteSpace ( val ) )
580+ {
581+ Messages . printArgumentError ( arg , argindex , "" ) ;
582+ return false ;
583+ }
584+
591585 //existing dir - ok
592- if ( Directory . Exists ( arg ) )
586+ if ( Directory . Exists ( val ) )
593587 {
594- Datnik . artifactsFolderPath = arg ;
588+ Datnik . artifactsFolderPath = val ;
595589 return true ;
596590 }
597591 else
@@ -610,7 +604,4 @@ internal static bool readArtifactsPathArgument(string arg, int argindex)
610604 }
611605 }
612606 }
613- }
614- // If we have an error and thus not able to set the datnik
615- // field, we should reset it. Otherwise we might get half-set datnik
616- // structure or previous command left-overs in the future
607+ }
0 commit comments