Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: Argument file support #36

Open
LightTempler opened this issue Apr 18, 2017 · 1 comment
Open

Suggestion: Argument file support #36

LightTempler opened this issue Apr 18, 2017 · 1 comment

Comments

@LightTempler
Copy link

For use cases like Windows Planned Tasks or longer, auto generated commandlines using a textfile instead of commandline has advantages. I just checked successfully, a single line of code is enough to get full argument file support for CommandLineParser :

MyApp.exe "C:\Configs\MyCmdlineFile.txt"

VB.NET (checked)

Sub Main(args() As String)

Dim MyOptionsClass As new cMyOptionsClass
Dim clParser As New CommandLineParser.CommandLineParser
Try
     clParser.ExtractArgumentAttributes(MyOptionsClass)

    ' JUST ADD THIS LINE:
    If args IsNot Nothing AndAlso args.Count = 1 AndAlso File.Exists(args(0)) = True Then args= File.ReadAllText(args(0)).Trim.Split(New String(){" ", vbCrLf}, StringSplitOptions.RemoveEmptyEntries)

    clParser.ParseCommandLine(args)

    ' Here we go using values ...

    Catch clEx As CommandLineException
            Console.WriteLine(clEx.Message)

    Catch ex As Exception
            Console.WriteLine(Ex.Message)
End Try
End Sub

C# (unchecked!, sorry)

static class MyApp
{	public static void Main(string[] args)
	{
		cMyOptionsClass MyOptionsClass = new cMyOptionsClass();
		CommandLineParser.CommandLineParser clParser = new CommandLineParser.CommandLineParser();
		try {
			clParser.ExtractArgumentAttributes(MyOptionsClass);

			// JUST ADD THIS LINE:
			if (args != null && args.Count == 1 && File.Exists(args(0)) == true)
				args = File.ReadAllText(args(0)).Trim.Split(new string[] {
					" ",
					Strings.Chr(13) + Strings.Chr(10)
				}, StringSplitOptions.RemoveEmptyEntries);

			clParser.ParseCommandLine(args);

			// Here we go using values ...

		} catch (CommandLineException clEx) {
			Console.WriteLine(clEx.Message);

		} catch (Exception ex) {
			Console.WriteLine(ex.Message);
		}
	}
}

Maybe this could be a switchable, build-in feature in a further version or it is worth to add to docu.

@alexandre-lecoq
Copy link
Contributor

IMHO, from a code perspective, this is better done outside ParseCommandLine as in the example.
For the scheduling use case, this could also be done by generating bat files or ps1 files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants