Skip to content

CLI Settings Validation #217

Answered by patriksvensson
turp asked this question in Q&A
Jan 9, 2021 · 2 comments · 4 replies
Discussion options

You must be logged in to vote

@turp Here is an example of how to validate arguments/options, and how to set arguments as optional/required and option values as optional/required. Reach out if you have any questions. Below the code example, there are some images showing the results of different operations.

Code

using Spectre.Console;
using Spectre.Console.Cli;
using System;
using System.ComponentModel;

namespace ConsoleApp9
{
    public class Program
    {
        public static int Main(string[] args)
        {
            var app = new CommandApp<MyCommand>();
            return app.Run(args);
        }
    }

    public sealed class MyCommand : Command<MyCommandSettings>
    {
        // Validate as part of the comm…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@turp
Comment options

@osmant
Comment options

@turp
Comment options

@patriksvensson
Comment options

Answer selected by patriksvensson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants