GithubHelp home page GithubHelp logo

Sub-commands? about oakton HOT 3 CLOSED

jasperfx avatar jasperfx commented on July 23, 2024
Sub-commands?

from oakton.

Comments (3)

cocowalla avatar cocowalla commented on July 23, 2024 1

For reference, I worked around this by handling the top level commands myself, then building a CommandExecutor for the specified command: Gist

@jeremydmiller BTW, I really like how simple yet well-featured this library is compared to the bigger ones!

from oakton.

jeremydmiller avatar jeremydmiller commented on July 23, 2024

You can use arguments to effect sub commands. Your Oakton command can vary on what it actually does by just doing a switch in the Execute on the argument. Oakton was originally built in the FubuCore days -- for better or worse -- as a way to build tools like the git cli

from oakton.

cocowalla avatar cocowalla commented on July 23, 2024

Do you mean using something like this:

[Description("Work with volumes", Name = "volume")]
public class VolumeCommand : OaktonAsyncCommand<VolumeInput>
{
	private readonly AppConfig appConfig;

	public VolumeCommand(AppConfig appConfig)
	{
		this.appConfig = appConfig;

		Usage("Work with a volume").Arguments(x => x.Action, x => x.Name);
	}

	public override async Task<bool> Execute(VolumeInput input)
	{
		// Switch on input.Action here
	}
}

public class VolumeInput
{
    public CommandAction Action { get; set; } = VolumeAction.ls;
    public string Name { get; set; };

    public enum CommandAction
    {
        create,
        ls,
        inspect,
        rm,
    }
}

Let's say I also wanted a command my-app volume ls, i.e. the ls action, but without any arguments - any idea how I could achieve this while still keeping the CommandUsage from the above code working?

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.