GithubHelp home page GithubHelp logo

Comments (5)

aidanjryan avatar aidanjryan commented on July 23, 2024

That change was in my PR, definitely did not intend to break anything. Can you share a command definition that exhibits this problem so we can write a test?

from oakton.

kae avatar kae commented on July 23, 2024

@aidanjryan
In my case it was

        [Oakton.Description("WebApi publish endpoint")]
	public class ListenCommand : BaseCommand<ListenInput> {
		public ListenCommand() {
			this.Usage("Listen to commands on default port").Arguments();
			this.Usage("Listen to commands").Arguments(i => i.Port);
		}
...

and model

	public class ListenInput : BaseInput {
		[Description("Listening on defined port")]
		public int Port { get; set; } = 12345;
		[Description("Get binaries"), FlagAlias("withBinaries", 'b')]
		public bool WithBinariesFlag { get; set; }
		[FlagAlias("restricted", 'r'), Description("Restrict to localhost")]
		public bool RestrictedFlag { get; set; }
	}

	public class BaseInput {
		[Description("Consul token"), FlagAlias("token", 't')]
		public string ConsulTokenFlag { get; set; }
		[Description("Consul HTTP endpoint address"), FlagAlias("http", 'h')]
		public string ConsulHttpFlag { get; set; }
		[Description("Timeout for waiting rpc response"), FlagAlias("timeout", 'i')]
		public int TimeoutFlag { get; set; } = 30;
		[Description("Environment name for settings discovery"), FlagAlias("env", 'e')]
		public string EnvironmentFlag { get; set; } = "local";
	}

with command line listen -e local

But I think it would break any case, with custom usage of 'optional' arguments

from oakton.

kae avatar kae commented on July 23, 2024

@aidanjryan
If there are some questions about my example, I can provide more information.

from oakton.

aidanjryan avatar aidanjryan commented on July 23, 2024

@kae Sorry I'm just getting around to reproducing this. I see where building input from usages is failing when all arguments are optional. Could you explain what you meant here?

This change missing "configuration" of usages in constructor of command and always validate on "default" usage with all arguments.

from oakton.

aidanjryan avatar aidanjryan commented on July 23, 2024

@kae Nevermind! I see what you mean - when the usages are built in isolation without the command constructor self-configuring the usages, custom usages aren't present.

This is a catch-22 for the purpose of the "BeforeBuild" hook -- the idea was to allow a DI container to be configured based on the input, before commands are constructed, in case some DI config is required based on the input.

I think what's required is splitting BuildInput's two responsibilities of creating and validating the input. I'll work on a fix now.

from oakton.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.