Skip to content
This repository has been archived by the owner on Mar 16, 2024. It is now read-only.

Commit

Permalink
feat: Use file input over pipe input.
Browse files Browse the repository at this point in the history
  • Loading branch information
just-seba committed Mar 2, 2024
1 parent f9e1bee commit 42af193
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 22 deletions.
23 changes: 15 additions & 8 deletions src/CodeButler/CodeButler.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,25 @@ public static async Task<int> Main(string[] args)
getDefaultValue: () => false
);

var inputFileArgMeta = new
{
Name = "input",
Description = "Path to input file or piped input."
};

var inputFileArg = Console.IsInputRedirected
? null
: new Argument<FileInfo>(
name: "Input",
description: "Path to input file or piped input."
? new Argument<FileInfo?>(
name: inputFileArgMeta.Name,
description: inputFileArgMeta.Description,
getDefaultValue: () => null
)
: new Argument<FileInfo?>(
name: inputFileArgMeta.Name,
description: inputFileArgMeta.Description
);

rootCommand.AddOption(noSortMemberByAlphabetOption);
if (inputFileArg is not null)
{
rootCommand.AddArgument(inputFileArg);
}
rootCommand.AddArgument(inputFileArg);

rootCommand.SetHandler(
RootCommandHandler.Handle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace CodeButler;
public class RootCommandConfigurationBinder : BinderBase<RootCommandConfiguration>
{
private readonly Option<bool> _noSortMemberByAlphabet;
private readonly Argument<FileInfo>? _file;
private readonly Argument<FileInfo?> _file;

public RootCommandConfigurationBinder(
Option<bool> noSortMemberByAlphabet,
Argument<FileInfo>? file
Argument<FileInfo?> file
)
{
_noSortMemberByAlphabet = noSortMemberByAlphabet;
Expand All @@ -22,18 +22,8 @@ protected override RootCommandConfiguration GetBoundValue(BindingContext binding
{
var parseResult = bindingContext.ParseResult;

InputOutputMode mode;
FileInfo? file;
if (_file is null)
{
mode = InputOutputMode.Console;
file = null;
}
else
{
mode = InputOutputMode.File;
file = parseResult.GetValueForArgument(_file);
}
var file = parseResult.GetValueForArgument(_file);
var mode = file is null ? InputOutputMode.Console : InputOutputMode.File;

return new RootCommandConfiguration
{
Expand Down

0 comments on commit 42af193

Please sign in to comment.