Skip to content

Arguments roundtrip; from class to arguments, and from arguments to class #76

@vpenades

Description

@vpenades

given a command class:

[CliCommand]
public class SomeComamnd
{
    [CliOption]
    public string SomeProperty { get; set; }
}

DotMake.CommandLine is designed to popupate the class properties from the parsed arguments.

Now, I would like to know if it's possible to do the reverse operation, that is, having an already populated command class, to retrieve the argument list that could be used to re-populate it, as in:

var command = new SomeCommand();
command.SomeProperty = "Hello World";

var arguments = Cli.GetArgsFrom(command); // this would generate a  [ "--some-property", "hello world" ]

Process.Start("server.exe", arguments);

The reasoning is this:

Given I have a Client-Server architecture where the server is a command line application.

The client defines the arguments to be parsed by the server.

If the client and the server share the same command classes via a shared library,

  • The client could populate SomeCommand, and call the server with the arguments provided by Cli.GetArgsFrom(command)
  • The server app would use the SomeCommand class to parse the arguments.

This is essentially doing a class -> arguments -> class roundtrip, closing the circle.

This has the advantage of keeping both the client and server in sync with any argument parameter changes. Also makes things easier for the client to build the list of arguments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions