주 메뉴 열기

wwiki β

CommandLineParser

Jhkim (토론 | 기여)님의 2022년 10월 12일 (수) 04:54 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

https://github.com/commandlineparser/commandline

C:\Project> Nuget Install CommandLineParser

샘플소스편집

using CommandLine;
using System;
using System.Data;
using System.IO;
using System.Linq;

namespace refNotifier
{
    public class Options
    {
        [Option('f', "file", Required = true, HelpText = "데이터 파일을 지정합니다.")]
        public string FilePath { get; set; }
        
        [Option('i', "min", Required = false, HelpText = "최소값을 지정합니다.")]
        public decimal Min { get; set; }

        [Option('a', "max", Required = false, HelpText = "최대값을 지정합니다.")]
        public decimal Max { get; set; }

        [Option('v', "verbose", Required = false, HelpText = "Set output to verbose messages.")]
        public bool Verbose { get; set; }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments<Options>(args)
                   .WithParsed<Options>(o =>
                   {
                       if (o.Verbose)
                       {
                           Console.WriteLine($"Verbose output enabled. Current Arguments: -v {o.Verbose}");
                           Console.WriteLine("Quick Start Example! App is in Verbose mode!");
                       }
                       else
                       {
                           Console.WriteLine($"Current Arguments: -v {o.Verbose}");
                           Console.WriteLine("Quick Start Example!");
                       }
                   });
        }
    }
}