Exemplo n.º 1
0
Arquivo: Get.cs Projeto: giuliov/s3e
        protected override void Initialise(CommandLine cl)
        {
            if (cl.args.Count < 1 || cl.args.Count > 2)
            {
                throw new SyntaxException("The get command requires one or two parameters");
            }

            big = cl.options.ContainsKey(typeof(Big));
            sub = cl.options.ContainsKey(typeof(Sub));
            if (big && sub)
            {
                throw new SyntaxException("The /big option is not currently compatible with the /sub option");
            }
            md5 = cl.options.ContainsKey(typeof(s3.Options.Md5));
            if (cl.options.ContainsKey(typeof(s3.Options.Install)))
            {
                if (Utils.IsLinux)
                {
                    throw new SyntaxException("The /install option is not currently supported on Linux");
                }
                install = cl.options[typeof(s3.Options.Install)] as s3.Options.Install;
            }
            if (cl.options.ContainsKey(typeof(s3.Options.Rex)))
            {
                if (big)
                {
                    throw new SyntaxException("The /rex option is not compatible with the /big option");
                }
                regex = new Regex((cl.options[typeof(s3.Options.Rex)] as s3.Options.Rex).Parameter, RegexOptions.Compiled);
            }

            resource = cl.args[0];
            int firstSlash = resource.IndexOf("/");

            if (firstSlash == -1)
            {
                if (!sub)
                {
                    throw new SyntaxException(slashRequiredError);
                }
                bucket = resource;
                key    = "";
            }
            else
            {
                bucket = resource.Substring(0, firstSlash);
                key    = resource.Substring(firstSlash + 1);
                if (sub && !key.EndsWith("/"))
                {
                    throw new SyntaxException("With the /sub option, the first parameter must be just a bucket name or must end with a slash (/)");
                }
            }

            if (!sub)
            {
                if (cl.args.Count == 1)
                {
                    int lastSlash = resource.LastIndexOf("/");
                    if (lastSlash == -1)
                    {
                        throw new SyntaxException(slashRequiredError);
                    }
                    filename         = resource.Substring(lastSlash + 1);
                    explicitFilename = false;
                }
                else
                {
                    filename         = cl.args[1];
                    explicitFilename = true;
                }
            }
            else
            {
                if (cl.args.Count == 1)
                {
                    filename = ".";
                }
                else
                {
                    filename = cl.args[1];
                    //if (!Directory.Exists(filename))
                    //    throw new SyntaxException("With the /sub option, the second parameter must be an existing directory");
                }
            }
        }
Exemplo n.º 2
0
        protected override void Initialise(CommandLine cl)
        {
            if (cl.args.Count < 1 || cl.args.Count > 2)
                throw new SyntaxException("The get command requires one or two parameters");

            big = cl.options.ContainsKey(typeof(Big));
            sub = cl.options.ContainsKey(typeof(Sub));
            if (big && sub) throw new SyntaxException("The /big option is not currently compatible with the /sub option");
            md5 = cl.options.ContainsKey(typeof(s3.Options.Md5));
            if(cl.options.ContainsKey(typeof(s3.Options.Install)))
            {
                if (Utils.IsLinux) throw new SyntaxException("The /install option is not currently supported on Linux");
                install =  cl.options[typeof(s3.Options.Install)] as s3.Options.Install;
            }
            if (cl.options.ContainsKey(typeof(s3.Options.Rex)))
            {
                if (big) throw new SyntaxException("The /rex option is not compatible with the /big option");
                regex = new Regex((cl.options[typeof(s3.Options.Rex)] as s3.Options.Rex).Parameter, RegexOptions.Compiled);
            }

            resource = cl.args[0];
            int firstSlash = resource.IndexOf("/");
            if (firstSlash == -1)
            {
                if (!sub)
                    throw new SyntaxException(slashRequiredError);
                bucket = resource;
                key = "";
            }
            else
            {
                bucket = resource.Substring(0, firstSlash);
                key = resource.Substring(firstSlash + 1);
                if (sub && !key.EndsWith("/"))
                    throw new SyntaxException("With the /sub option, the first parameter must be just a bucket name or must end with a slash (/)");
            }

            if (!sub)
            {
                if (cl.args.Count == 1)
                {
                    int lastSlash = resource.LastIndexOf("/");
                    if (lastSlash == -1)
                        throw new SyntaxException(slashRequiredError);
                    filename = resource.Substring(lastSlash + 1);
                    explicitFilename = false;
                }
                else
                {
                    filename = cl.args[1];
                    explicitFilename = true;
                }
            }
            else
            {
                if (cl.args.Count == 1)
                    filename = ".";
                else
                {
                    filename = cl.args[1];
                    //if (!Directory.Exists(filename))
                    //    throw new SyntaxException("With the /sub option, the second parameter must be an existing directory");
                }
            }
        }