dotnet / dotnet/command-line-api

Unable to Access Command Line Arguments

Open
#1,178 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

I want to call a function 'A' from a command line handler which is not present in the same .cs file.
When I do a run, the handler is passing null values to the function ' A' parameters.
Function 'A' only gets called, if I call another function 'B' from the handler which is in the same file and then call my function 'A'.
I don't want to use an extra function to call the function 'A'.

From the below code I want to remove the function named 'InvokeParseDDL' and directly want to the function ParseDDL which is in the Parser class.

static int Main(string[] args)
{
var ddlFilePath = new Option("--ddl", "DDL File Path")
{
IsRequired = true
};

var outputFilePath = new Option(new[] { "--outputPath", "-o" }, "Output File Path");
outputFilePath.IsRequired = true;

var cmd = new RootCommand
{
ddlFilePath,
new Option("--csv", "CSV File Path"),
new Option(new[]{ "--model","-m"},"File Type"),
outputFilePath
};

cmd.Handler = CommandHandler.Create(InvokeParseDDL);
//cmd.Handler = CommandHandler.Create(Parser.ParseDDL);
return cmd.Invoke(args);
}

static void InvokeParseDDL(string ddl, string csv, string model, string outputPath)
{
Console.WriteLine(ddl + csv + outputPath + model);
Parser.ParseDDL(ddl, csv, model, outputPath);
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.