Skip to content

Commit

Permalink
Merge pull request #132 from verdie-g/glob-0-error
Browse files Browse the repository at this point in the history
Exit with an error if a glob didn't expand to any file
  • Loading branch information
mganss authored Sep 10, 2019
2 parents ed5925e + d2ca92c commit a658737
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions XmlSchemaClassGenerator.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,32 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l
{ "cc|complexTypesForCollections", "generate complex types for collections (default is true)", v => generateComplexTypesForCollections = v != null },
};

var files = options.Parse(args);
var globsAndUris = options.Parse(args);

if (showHelp)
{
ShowHelp(options);
return;
}

files = files.SelectMany(f => Glob.ExpandNames(f)).Concat(files.Where(f => Uri.IsWellFormedUriString(f, UriKind.Absolute))).ToList();
var uris = new List<string>();
foreach (var globOrUri in globsAndUris)
{
if (Uri.IsWellFormedUriString(globOrUri, UriKind.Absolute))
{
uris.Add(globOrUri);
continue;
}

var expandedGlob = Glob.ExpandNames(globOrUri).ToList();
if (expandedGlob.Count == 0)
{
System.Console.WriteLine($"No files found for '{globOrUri}'");
Environment.Exit(1);
}

uris.AddRange(expandedGlob);
}

var namespaceMap = namespaces.Select(n => ParseNamespace(n, namespacePrefix)).ToNamespaceProvider(key =>
{
Expand Down Expand Up @@ -150,7 +167,7 @@ A file name may be given by appending a pipe sign (|) followed by a file name (l

if (verbose) { generator.Log = s => System.Console.Out.WriteLine(s); }

generator.Generate(files);
generator.Generate(uris);
}

static KeyValuePair<NamespaceKey, string> ParseNamespace(string nsArg, string namespacePrefix)
Expand Down

0 comments on commit a658737

Please sign in to comment.