public void ParseSnippetPathTest()
        {
            var path = VisualStudioSnippet.FixupSnippetPath(@"~\2017\Visual C#\My Code Snippets");

            Console.WriteLine(path);
            Assert.IsFalse(path.Contains("~\\"));
            Assert.IsTrue(path ==
                          Path.Combine(VisualStudioSnippet.GetUserVisualStudioVersionFolder("2017"), "Visual C#\\My Code Snippets"));
        }
Exemple #2
0
        public override void Parse()
        {
            Mode = ParseStringParameterSwitch("-m", null);
            if (string.IsNullOrEmpty(Mode))
            {
                Mode = ParseStringParameterSwitch("--mode", "vs-vscode");
            }
            Mode = Mode.ToLower();

            SourceFileOrDirectory = Args[0];
            SourceFileOrDirectory = Environment.ExpandEnvironmentVariables(SourceFileOrDirectory);

            TargetFile = ParseStringParameterSwitch("-o", null);
            if (string.IsNullOrEmpty(TargetFile))
            {
                TargetFile = ParseStringParameterSwitch("--output", null);
            }

            if (Mode == "vs-vscode")
            {
                if (string.IsNullOrEmpty(TargetFile))
                {
                    TargetFile = "~\\visualstudio-exported.code-snippets";
                }
                TargetFile = VsCodeSnippet.FixupSnippetPath(TargetFile);
            }


            Verbose = ParseParameterSwitch("-v");
            Recurse = ParseParameterSwitch("-r");

            ShowFileInExplorer = ParseParameterSwitch("-d");



            SnippetPrefix = ParseStringParameterSwitch("-p", null);
            if (string.IsNullOrEmpty(SnippetPrefix))
            {
                SnippetPrefix = ParseStringParameterSwitch("--prefix", null);
            }


            // Fix up for Visual Studio Snippet Path
            if (Mode.StartsWith("vs-"))
            {
                SourceFileOrDirectory = VisualStudioSnippet.FixupSnippetPath(SourceFileOrDirectory);
            }

            if (!string.IsNullOrEmpty(SourceFileOrDirectory) &&
                Directory.Exists(SourceFileOrDirectory))
            {
                DirectoryMode = true;
            }

            if (string.IsNullOrEmpty(SourceFileOrDirectory))
            {
                throw new ArgumentException("Source File or Directory shouldn't be empty.");
            }


            if (!DirectoryMode && !File.Exists(SourceFileOrDirectory))
            {
                throw new ArgumentException("Source file or directory does not exist.");
            }
        }