0

我正在使用“CommandDotNet”在 CLI 工具中创建命令。而且我也添加了[SubCommand]属性但是“set”命令或其子命令“workdir”不起作用。以前添加的子命令工作正常。可能是什么问题呢?

CLITool.cs

[SubCommand]
public Configurations Set { get; set; }

配置.cs

    [Command(Description = "Use for additional configuration commands.")]
    public class Configurations
    {
        private static string configFile = FilePathUtility.Workdirectory;

        [DefaultMethod]
        public void SetDefaultCommand()
        {
            string workdir = File.ReadAllText(configFile);
            if (!string.IsNullOrWhiteSpace(workdir))
            {
                FeedbackUtility.output($"Working directory : {workdir}", ColorUtility.colorsettings.INFO);
            }else { FeedbackUtility.output($"Working directory has not set. Use \"clitool set workdir\" to set the working directory", ColorUtility.colorsettings.INFO); }
        }

        [Command(Description = "Set working directory")]
        public async Task WorkDir()
        {
            Console.WriteLine("\nSpecify working directory:");
            string workdir = Console.ReadLine();

            //Overwrites/Creates config file in temp folder with working directory string
            Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\temp\\");
            File.WriteAllText(configFile, workdir);

            FeedbackUtility.output("Successfully specified the working directory!", ColorUtility.colorsettings.SUCCESS);
        }
    }
4

0 回答 0