Skip to content

Commit

Permalink
Added support to specify a single source file
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabricio Ferreira committed Apr 24, 2024
1 parent c8ef49f commit 40874d2
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
17 changes: 12 additions & 5 deletions src/DocFxOpenApi/DocFxOpenApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ private void RunLogic()
_options.OutputFolder = _options.SpecFolder;
}

_message.Verbose($"Specification folder: {_options.SpecFolder}");
_message.Verbose($"Specification file/folder: {_options.SpecFolder ?? _options.SpecFile}");
_message.Verbose($"Output folder : {_options.OutputFolder}");
_message.Verbose($"Verbose : {_options.Verbose}");

if (!Directory.Exists(_options.SpecFolder))
if ((_options.SpecFolder ?? _options.SpecFile) == null)
{
_message.Error($"ERROR: Specification folder '{_options.SpecFolder}' doesn't exist.");
_message.Error($"ERROR: Specification folder/file '{_options.SpecSource}' doesn't exist.");
_returnvalue = 1;
return;
}
Expand All @@ -93,9 +93,16 @@ private void RunLogic()

private void ConvertOpenApiFiles()
{
foreach (var extension in _openApiFileExtensions)
if (_options.SpecFolder != null)
{
this.ConvertOpenApiFiles(extension);
foreach (var extension in _openApiFileExtensions)
{
this.ConvertOpenApiFiles(extension);
}
}
else
{
this.ConvertOpenApiFile(_options.SpecFile!);
}
}

Expand Down
46 changes: 39 additions & 7 deletions src/DocFxOpenApi/Domain/CommandlineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,61 @@

namespace DocFxOpenApi.Domain
{
using System.IO;
using CommandLine;

/// <summary>
/// Class for command line options.
/// Class for command line options.
/// </summary>
public class CommandlineOptions
{
/// <summary>
/// Gets or sets the folder with specifications.
/// Gets or sets the folder with specifications.
/// </summary>
[Option('s', "specfolder", Required = true, HelpText = "Folder containing the OpenAPI specification.")]
public string? SpecFolder { get; set; }
[Option('s', "specsource", Required = true, HelpText = "Folder or File containing the OpenAPI specification.")]
public string? SpecSource
{
get => SpecFolder ?? SpecFile;
set => SetSource(value);
}

/// <summary>
/// Gets or sets the output folder.
/// Gets or sets the output folder.
/// </summary>
[Option('o', "outputfolder", Required = false, HelpText = "Folder to write the resulting specifications in.")]
public string? OutputFolder { get; set; }

/// <summary>
/// Gets or sets a value indicating whether verbose information is shown in the output.
/// Gets or sets a value indicating whether verbose information is shown in the output.
/// </summary>
[Option('v', "verbose", Required = false, HelpText = "Show verbose messages.")]
public bool Verbose { get; set; }

/// <summary>
/// Gets the folder with specifications, if the source is a folder.
/// </summary>
public string? SpecFolder { get; private set; }

/// <summary>
/// Gets the file with specifications, if the source is a file.
/// </summary>
public string? SpecFile { get; private set; }

private void SetSource(string? value)
{
if (value == null)
{
return;
}

if (Directory.Exists(value))
{
SpecFolder = value;
}
else if (File.Exists(value))
{
SpecFile = value;
}
}
}
}
}

0 comments on commit 40874d2

Please sign in to comment.