public int Invoke()
        {
            // Remove when we incorporate into real help
            if (Help2)
            {
                var rootCommandSource = CommandSource.Create <DotnetCommand>() as DotnetCommandCommandSource;
                var commandSource     = rootCommandSource?.NewCommandCommand;
                return(DisplayListHelp(UxLevel, RenderTo, RenderToFileName, commandSource, true));
            }
            var commonTemplates = "console, classlib";
            var data            = TemplateData.SampleData; // get real data here

            var selector = new Selector();

            selector.AddRange(data.Select(template => new SelectorItem(template.ShortName,
                                                                       template.TemplateName,
                                                                       commonTemplates.Contains(template.ShortName))));
            selector.Sorted = true;
            var shortName = Cli.GetFromPrompt(selector, RenderTo, UxLevel);

            Console.WriteLine(string.IsNullOrWhiteSpace(shortName)
                                ? "Enter a template name or a command"
                                : $"Run {shortName}");
            return(0);
        }
Beispiel #2
0
        //static int Main_with_direct_execution(string[] args)
        //{
        //             return CommandSource.Run<CliRoot>(args, Run);

        //    static int Run(CliRootCommandSourceResult result)
        //    {
        //        return result switch
        //        {
        //            FindCommandSourceResult => result.CreateInstance().FindAsync(), // validation here and values can be changed
        //            ListCommandSourceResult => List(), //
        //            _ => 1
        //        };
        //    }
        //}

        static async Task <int> Main_what_really_happens(string[] args)
        {
            return(0);

            var commandSource = CommandSource.Create <CliRoot>() as CliRootCommandSource;
            // modify System.CommandLine elements here

            var commandSourceResult = commandSource.Parse(string.Join("", args));

            if (commandSourceResult.EarlyReturn)
            {
                return(commandSourceResult.ExitCode);
            }
            var cliRootResult = commandSourceResult as CliRootCommandSourceResult;

            // Property validation and modify if accessible
            switch (cliRootResult)
            {
            case FindCommandSourceResult:
            // validation here and values can be changed
            case ListCommandSourceResult:
            default:
                break;
            }
            // if you didn’t early return on help, etc, Execute does nothing
            var exitCode = await commandSourceResult.RunAsync();

            return(exitCode);
        }
 /// <summary>
 /// Lists templates containing the specified template name.If no name is specified, lists all templates.
 /// </summary>
 /// <param name="columns">Columns to display</param>
 /// <param name="type">Filters templates based on available types.Predefined values are 'project' and 'item'.</param>
 /// <param name="language">Filters templates based on language and specifies the language of the template to create.</param>
 public int ListCommand(
     string[] columns,
     TemplateType type,
     [Aliases("--lang")]
     string language)
 {
     // Remove when we incorporate into real help
     if (Help2)
     {
         var rootCommandSource = CommandSource.Create <DotnetCommand>() as DotnetCommandCommandSource;
         var commandSource     = rootCommandSource?.NewCommandCommand.ListCommand;
         return(DisplayListHelp(UxLevel, RenderTo, RenderToFileName, commandSource));
     }
     return(DisplayList(UxLevel, RenderTo, RenderToFileName, columns, type, language));
Beispiel #4
0
        static int Main_with_CliModifications(string[] args)
        {
            return(0);

            var commandSource = CommandSource.Create <CliRoot>() as CliRootCommandSource;
            //_ = commandSource ?? throw new InvalidOperationException("CommandSource not found or unexpected type");

            //// Modify commandSource.Command CLI tree
            //// For example, might need complex default, or rarely to add additional elements,
            //// Note: The CommandSource structure makes it easy to find what you want to change
            //commandSource.Find.IntArg.SetDefaultValue(DateTime.Now.DayOfYear);

            //return commandSource.Parse(args).Run();
        }
Beispiel #5
0
 static int Main(string[] args)
 {
     Console.WriteLine("Hello World!");
     return(CommandSource.Create(nameof(Format)).Run(args));
 }