1 
  
    2 
  
    3 
  
    4 
  
    5 
  
    6 using System;
  
    7 using System.Collections;
  
    8 using paths;
  
    9 
  
   10 int main(int argc, const char** argv)
  
   11 {
  
   12     try
  
   13     {
  
   14         bool verbose = false;
  
   15         bool recursive = false;
  
   16         List<string> files;
  
   17         for (int i = 1; i < argc; ++i;)
  
   18         {
  
   19             string arg = argv[i];
  
   20             if (arg.StartsWith("--"))
  
   21             {
  
   22                 if (arg == "--help")
  
   23                 {
  
   24                     PrintHelp();
  
   25                     return 1;
  
   26                 }
  
   27                 else if (arg == "--verbose")
  
   28                 {
  
   29                     verbose = true;
  
   30                 }
  
   31                 else if (arg == "--recursive")
  
   32                 {
  
   33                     recursive = true;
  
   34                 }
  
   35                 else
  
   36                 {
  
   37                     throw Exception("unknown argument '" + arg + "'");
  
   38                 }
  
   39             }
  
   40             else if (arg.StartsWith("-"))
  
   41             {
  
   42                 string options = arg.Substring(1);
  
   43                 if (options.IsEmpty())
  
   44                 {
  
   45                     throw Exception("unknown argument '" + arg + "'");
  
   46                 }
  
   47                 else
  
   48                 {
  
   49                     bool unknown = false;
  
   50                     string uo;
  
   51                     for (char o : options)
  
   52                     {
  
   53                         switch (o)
  
   54                         {
  
   55                             case 'h':
  
   56                             {
  
   57                                 PrintHelp();
  
   58                                 return 1;
  
   59                             }
  
   60                             case 'v':
  
   61                             {
  
   62                                 verbose = true;
  
   63                                 break;
  
   64                             }
  
   65                             case 'r':
  
   66                             {
  
   67                                 recursive = true;
  
   68                                 break;
  
   69                             }
  
   70                             default:
  
   71                             {
  
   72                                 unknown = true;
  
   73                                 uo.Append(o);
  
   74                                 break;
  
   75                             }
  
   76                         }
  
   77                         if (unknown)
  
   78                         {
  
   79                             throw Exception("unknown option '-" + uo + "'");
  
   80                         }
  
   81                     }
  
   82                 }
  
   83             }
  
   84             else
  
   85             {
  
   86                 files.Add(arg);
  
   87             }
  
   88         }
  
   89         if (!HasEnv("SHELL"))
  
   90         {
  
   91             files = Expand(files);
  
   92         }
  
   93         Remove(files, verbose, recursive);
  
   94     }
  
   95     catch (const Exception& ex)
  
   96     {
  
   97         Console.Error() << ex.ToString() << endl();
  
   98         return 1;
  
   99     }
  
  100     return 0;
  
  101 }