예제 #1
0
        //参数解析
        public static void instruct_getopt(string[] args, CommandLineArgumentParser argments)
        {
            if (args.Length == 0 || !(argments.Has("-u") || argments.Has("-p") || argments.Has("-g")))
            {
                helpMe();
                return;
            }

            try
            {
                if (argments.Has("-u") && argments.Has("-p") && argments.Has("-g"))
                {
                    //Console.WriteLine("添加用户和组参数为:" + argments.Get("-u").Next + "," + argments.Get("-p").Next + "," + argments.Get("-g").Next);
                    AddAccountAndGroup(argments.Get("-u").Next, argments.Get("-p").Next, argments.Get("-g").Next);
                    Console.WriteLine("添加用户:" + argments.Get("-u").Next + ",密码为:" + argments.Get("-p").Next + "到" + argments.Get("-g").Next + "组成功!");
                    return;
                }

                if (argments.Has("-u") && argments.Has("-p"))
                {
                    //Console.WriteLine("添加用户参数为:" + argments.Get("-u").Next + "," + argments.Get("-p").Next);
                    AddAccount(argments.Get("-u").Next, argments.Get("-p").Next);
                    Console.WriteLine("添加用户:" + argments.Get("-u").Next + ",密码:" + argments.Get("-p").Next + "成功!");
                    return;
                }


                if (argments.Has("-u") && argments.Has("-g"))
                {
                    //Console.WriteLine("添加用户组参数为:" + argments.Get("-u").Next + "," + argments.Get("-g").Next);
                    AddGroup(argments.Get("-u").Next, argments.Get("-g").Next);
                    Console.WriteLine("把用户:" + argments.Get("-u").Next + "添加到" + argments.Get("-g").Next + "组成功!");
                    return;
                }
                helpMe();
                return;
            }
            catch (Exception err)
            {
                Console.WriteLine("参数异常!" + err.Message);
                //throw new Exception("参数异常!");
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            var argments = CommandLineArgumentParser.Parse(args);

            instruct_getopt(args, argments);
        }