Пример #1
0
    /*
     * TODO:
     *  - use my command line args library
     *  - implement mode to delete white space from the file
     *  - implement option to show full file vs. only the affected lines
     */
    public static void Main(string[] args)
    {
        if (args.Length < 1)
        {
            Usage();
        }

        string path  = null;
        bool   aflag = false;

        CommandLineProcessor argsProcessor = new CommandLineProcessor();

        argsProcessor.RegisterOptionMatchHandler("a", requiresArgument: false, (sender, o) => {
            aflag = true;
        });
        argsProcessor.RegisterOptionMatchHandler("f", requiresArgument: true, (sender, o) => {
            path = o.Argument;
        });
        argsProcessor.RegisterOptionMatchHandler(CommandLineProcessor.InvalidOptionIdentifier, (sender, o) => {
            Usage();
        });
        argsProcessor.ProcessCommandLineArgs(args);

        if (string.IsNullOrEmpty(path) || !File.Exists(path))
        {
            Console.WriteLine("invalid path or not a file: {0}", path);
            Quit();
        }

        FileInfo file = new FileInfo(path);

        Print(file, printAll: aflag);
    }
        public void Invalid_Argument_2(params string[] args)
        {
            CommandLineProcessor cmdline = new CommandLineProcessor();

            cmdline.RegisterOptionMatchHandler("a", true, (sender, e) => { });

            cmdline.ProcessCommandLineArgs(args);

            Assert.That(cmdline.ArgCount, Is.EqualTo(1));

            Assert.That(cmdline.InvalidArgs.Count, Is.EqualTo(1));
        }
        public void Option_NoArg_1(params string[] args)
        {
            CommandLineProcessor cmdline = new CommandLineProcessor();

            cmdline.RegisterOptionMatchHandler("a", (sender, e) => { });

            cmdline.ProcessCommandLineArgs(args);

            Assert.That(cmdline.ArgCount, Is.EqualTo(1));

            IEnumerable <string> emptylist = new List <string>(0);

            Assert.That(cmdline.InvalidArgs, Is.EquivalentTo(emptylist));
        }
Пример #4
0
    public static void Main(string[] args)
    {
        bool listener_flag = false;             // Listen to network requests
        bool reader_flag   = false;             // Read the dictionary file

        string readerHandle = null;

        CommandLineProcessor argsProcessor = new CommandLineProcessor();

        argsProcessor.RegisterOptionMatchHandler("L", requiresArgument: false, (sender, o) => {
            listener_flag = true;
        });
        argsProcessor.RegisterOptionMatchHandler("R", requiresArgument: false, (sender, o) => {
            reader_flag = true;
        });
        argsProcessor.RegisterOptionMatchHandler("H", requiresArgument: true, (sender, o) => {
            readerHandle = o.Argument;
        });
        argsProcessor.RegisterOptionMatchHandler(CommandLineProcessor.InvalidOptionIdentifier, (sender, o) => {
            //Usage();
            Environment.Exit(1);
        });
        argsProcessor.ProcessCommandLineArgs(args);

        if (listener_flag && reader_flag)
        {
            // Error!
            Environment.Exit(1);
        }

        if (listener_flag)
        {
            // run as the network Listener
            Listener();
        }

        if (reader_flag)
        {
            // run as the dictionary reader
            Reader(readerHandle);
        }

        // This is what the main app does
        ForkListener();
        ForkReader();
    }