class Object

Public Instance Methods

command_help(command) click to toggle source
# File lib/fileman/scripts/core.rb, line 32
def command_help(command)
        case command
        when "rename"
                rename_help("rename")
        when "rn"
                rename_help("rn")
        when "remove"
                remove_help("remove")
        when "rm"
                remove_help("rm")
        else
                puts "Command #{command} does not exist. Use 'fileman help' to find out about the usage".colorize(:red)
        end
end
get_rename_arguments() click to toggle source
# File lib/fileman/scripts/core.rb, line 68
def get_rename_arguments
        arguments = {}
        args = ARGV.clone
        args.shift(1) # ignore the first argument by removing them from the array
        arguments[:path] = args[0]
        arguments[:name] = args[1]
        options = get_rename_options
        arguments[:include_files] = options[:include_files]
        arguments[:ignore_ext] = options[:ignore_ext]
        arguments[:recursive] = options[:recursive]
        
        return arguments
end
get_rename_options() click to toggle source
# File lib/fileman/scripts/core.rb, line 47
def get_rename_options
        args = ARGV.clone
        args.shift(3) # ignore the first 2 arguments by removing them from the array
        options = {}
        if (args.size > 0)
                args.each { |x|
                        x.gsub('-', '').split('').each { |y|
                                case y
                                when 'i'
                                        options[:include_files] = true
                                when 'e'
                                        options[:ignore_ext] = true
                                when 'r'
                                        options[:recursive] = true
                                end
                        }
                }
        end
        return options
end
help() click to toggle source
# File lib/fileman/scripts/core.rb, line 6
def help
        text = "usage: fileman <command> [<args>]\n" +
        "\n" +
        "The fileman commands are:\n" +
        " rename, or rn\t Rename a folder as well as all its content with the same name\n" +
        " remove, or rm\t Delete a folder\n" +
        "\n" +
        "For more details about each command, use fileman <command> -h"
        puts text.colorize(:yellow)
end
remove() click to toggle source
# File lib/fileman/scripts/core.rb, line 99
def remove
        argsize = ARGV.size
        if argsize == 1
                puts "Missing argument(0 for 1). Use 'fileman help' to find out about the usage".colorize(:red)
        else
                folder_path = ARGV[1].downcase
                Fileman.remove folder_path
        end
end
remove_help(rename_command) click to toggle source
# File lib/fileman/scripts/core.rb, line 27
def remove_help(rename_command)
        text = "usage: fileman #{rename_command} <folder path>"
        puts text.colorize(:yellow)
end
rename() click to toggle source

Usage: fileman rn “your_folder_path” “new_name” -ie

# File lib/fileman/scripts/core.rb, line 83
def rename
        argsize = ARGV.size
        if argsize == 1
                puts "Missing argument(0 for 2..3). Use 'fileman help' to find out about the usage".colorize(:red)
        elsif argsize == 2
                puts "Missing argument(1 for 2..3). Use 'fileman help' to find out about the usage".colorize(:red)
        else
                args = get_rename_arguments
                options = {}
                options[:include_files] = true if args[:include_files]
                options[:ignore_ext] = true if args[:ignore_ext]
                options[:recursive] = true if args[:recursive]
                Fileman.rename(args[:path], args[:name], options) unless args[:error]
        end
end
rename_help(rename_command) click to toggle source
# File lib/fileman/scripts/core.rb, line 17
def rename_help(rename_command)
        text = "usage: fileman #{rename_command} <path> <new-name> [<args>]\n" +
        "\n" +
        "Optional arguments are:\n" +
        " -r\t Recursive rename. That means that if the path points to a folder, all its content will also be renamed\n" +
        " -i\t Include files so they are also renamed. This option implicitly uses recursive rename(no need to use the -r option)\n" +
        " -e\t Remove files extension. Only valid if the -i option is also specified" 
        puts text.colorize(:yellow)
end