GIS CLI commands

Dani_S 4,836 Reputation points
2025-12-12T11:02:22.9333333+00:00

Hi,

I would like to ask the following questions regarding my GIS CLI command in program file.

The GIS CLI commands used once by end-user.

1.Does the ShowHelp method is a good practice in CLI if not please fix.

I used in this case to show it:

// If no arguments are provided or help is requested, show help and exit.

if (args.Length == 0 || args[0] == "help" || args[0] == "--help" || args[0] == "-h")

{

ShowHelp();

return (int)ExitCode.AppError;

}

  1. This the command line:

<gis_input_file_path> <gis_target_format_option> <output_folder_path> <temp_folder_path> [Log <log_file_path>]"

[Log <log_file_path>]" is optional and handled in GetOptionalLogFolderPath method.

I want to add log level After Log or after <log_file_path> , in the appropriate place**.**

I use Log4Net. Can you please give me code to add this funcuality?

I added my logs files. In Log file -SetFile method there are these lines:

// Always enable all levels on the root logger for maximum diagnostic coverage

if (hierarchy != null)

{

 **hierarchy.Root.Level = hierarchy.LevelMap["ALL"];**

 **hierarchy.Configured = true;**

}

Take into account <log_file_path> can contains spaces and wasn't quoted that can broke the command line parser. Need to hndle this case also.

3.For the gis_input_file_path can contains spaces and wasn't quoted - is it ok?

// Attempt to repair args when input path contains spaces and wasn't quoted.

// Strategy:

// - Look for the first token after the command that matches a supported converter option.

// - If found, join intervening tokens into the input path.

// - Returns original args when no repair possible.

private static string[] TryRepairUnquotedInputArgs(string[] args, ConverterFactory factoryProbe)

{

if (args == null || args.Length < 3) return args;

var supported = new HashSet<string>(factoryProbe.GetSupportedOptions().Select(s => s.ToLowerInvariant()), StringComparer.OrdinalIgnoreCase);

// search for supported option token starting from index 2 (args[0]=command, args[1]=start of input)

for (int i = 2; i < args.Length; i++)

{

var token = args[i].Trim().ToLowerInvariant();

if (supported.Contains(token))

{

// found the format token at index i -> join args[1..i-1] into input path

var inputParts = args.Skip(1).Take(i - 1).ToArray();

var joinedInput = string.Join(" ", inputParts);

var rebuilt = new List<string>

{

args[0], // command

joinedInput, // joined input path

args[i] // target option

};

// append remaining args (output, temp, optional Log ...)

for (int j = i + 1; j < args.Length; j++)

rebuilt.Add(args[j]);

return rebuilt.ToArray();

}

}

// No supported option token found — return original args.

return args;

}

4.If you see more problem me please fix me me the code?

5.Please give a full code.

Thanks in advance.

ConversionResult.txt

ConverterFactory.txt

ConverterUtils.txt

IAppLogger.txt

Log.txt

Log4NetAdapter.txt

NullLogger.txt

Program.txt

ProgramIntegrationTest.txt

README.md.txt

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.