コード例 #1
0
 private static void CheckOptions(EncodeCommandLineOptions checkedOptions)
 {
     if (!checkedOptions.IsSetHelp && !checkedOptions.IsSetVersion)
     {
         if (!checkedOptions.IsSetInputFile && !checkedOptions.IsSetDirectory)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify a input file or a directory."));
         }
         if (!checkedOptions.IsSetFromEncoding)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify the input file current encoding."));
         }
         if (!checkedOptions.IsSetToEncoding)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "must specify the output file target encoding."));
         }
         if (checkedOptions.IsSetInputFile && WildcardCharacterHelper.IsContainsWildcard(checkedOptions.InputFile) &&
             checkedOptions.IsSetOutputFile)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "output file path has been set, so can only set one input file."));
         }
         if (checkedOptions.IsSetDirectory && checkedOptions.IsSetOutputFile)
         {
             throw new CommandLineException(string.Format(CultureInfo.CurrentCulture,
                                                          "Option used in invalid context -- {0}", "output file path has been set, so can not set a input directory."));
         }
     }
 }
コード例 #2
0
ファイル: GrepCommandLine.cs プロジェクト: softempire/Knifer
 private void StartGrep()
 {
     try
     {
         foreach (var item in options.FilePaths)
         {
             string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(item);
             if (options.IsSetDirectory)
             {
                 GrepDirectory(path);
             }
             else
             {
                 if (WildcardCharacterHelper.IsContainsWildcard(path))
                 {
                     string dir = path;
                     if (!path.Contains("\\") && !path.Contains("/"))
                     {
                         dir = Environment.CurrentDirectory + Path.DirectorySeparatorChar + path;
                     }
                     FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(dir)).GetFiles();
                     foreach (var file in files.OrderBy(f => f.LastWriteTime).ThenBy(f => f.Name))
                     {
                         Regex r = new Regex(WildcardCharacterHelper.TranslateWildcardToRegex(path));
                         if (r.IsMatch(file.FullName) || r.IsMatch(file.Name))
                         {
                             GrepFile(file.FullName);
                         }
                     }
                 }
                 else
                 {
                     GrepFile(path);
                 }
             }
         }
     }
     catch (ArgumentException ex)
     {
         RaiseCommandLineException(this, new CommandLineException("Path is invalid.", ex));
     }
     catch (CommandLineException ex)
     {
         RaiseCommandLineException(this, ex);
     }
 }
コード例 #3
0
        private void StartEncode()
        {
            try
            {
                if (options.IsSetInputFile)
                {
                    string path = WildcardCharacterHelper.TranslateWildcardFilePath(options.InputFile);
                    if (WildcardCharacterHelper.IsContainsWildcard(path))
                    {
                        FileInfo[] files = new DirectoryInfo(Path.GetDirectoryName(path)).GetFiles();
                        foreach (var file in files)
                        {
                            Regex r = new Regex(WildcardCharacterHelper.TranslateWildcardToRegex(path));
                            if (r.IsMatch(file.FullName) || r.IsMatch(file.Name))
                            {
                                EncodeFile(file.FullName);
                            }
                        }
                    }
                    else
                    {
                        EncodeFile(path);
                    }
                }

                if (options.IsSetDirectory)
                {
                    string path = WildcardCharacterHelper.TranslateWildcardDirectoryPath(options.Directory);
                    EncodeDirectory(path);
                }
            }
            catch (CommandLineException ex)
            {
                RaiseCommandLineException(this, ex);
            }
        }