微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

CommandDotNet 的子命令不起作用,尽管我在 C#

如何解决CommandDotNet 的子命令不起作用,尽管我在 C#

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

CLITool.cs

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

Configurations.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);
        }
    }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。