Module: Rmega::CLI::Helpers
- Defined in:
- lib/rmega/cli.rb
Instance Method Summary collapse
- #apply_cli_options ⇒ Object
- #apply_opt_parser_options(opts) ⇒ Object
- #cli_options ⇒ Object
- #cli_prompt_password ⇒ Object
- #cli_rescue ⇒ Object
- #configuration_filepath ⇒ Object
- #mega_url?(url) ⇒ Boolean
- #read_configuration_file ⇒ Object
- #traverse_storage(node, path, opts = {}) ⇒ Object
Instance Method Details
#apply_cli_options ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/rmega/cli.rb', line 38 def .each do |key, value| Rmega..__send__("#{key}=", value) end Rmega.logger.level = ::Logger::DEBUG if [:debug] Rmega..show_progress = true end |
#apply_opt_parser_options(opts) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rmega/cli.rb', line 46 def (opts) opts.on("-t NUM", "--thread_pool_size", "Number of threads to use") { |n| [:thread_pool_size] = n.to_i } opts.on("--proxy-addr ADDRESS", "Http proxy address") { |value| [:http_proxy_address] = value } opts.on("--proxy-port PORT", "Http proxy port") { |value| [:http_proxy_port] = value.to_i } opts.on("-u", "--user USER_EMAIL", "User email address") { |value| [:user] = value } opts.on("--pass [USER_PASSWORD]", "User password (if omitted will prompt for it)") { |value| [:pass] = value } opts.on("--debug", "Debug mode") { [:debug] = true } opts.on("-v", "--version", "Print the version number") { puts Rmega::VERSION puts Rmega::HOMEPAGE exit!(0) } end |
#cli_options ⇒ Object
8 9 10 |
# File 'lib/rmega/cli.rb', line 8 def $cli_options ||= {} end |
#cli_prompt_password ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rmega/cli.rb', line 12 def cli_prompt_password print("Enter password: ") password = STDIN.noecho(&:gets) password = password[0..-2] if password.end_with?("\n") puts return password end |
#cli_rescue ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/rmega/cli.rb', line 101 def cli_rescue read_configuration_file yield rescue Interrupt puts "\nInterrupted" rescue Exception => ex if [:debug] raise(ex) else $stderr.puts "\nERROR: #{ex.}" end end |
#configuration_filepath ⇒ Object
25 26 27 |
# File 'lib/rmega/cli.rb', line 25 def configuration_filepath File.('~/.rmega') end |
#mega_url?(url) ⇒ Boolean
21 22 23 |
# File 'lib/rmega/cli.rb', line 21 def mega_url?(url) Nodes::Factory.url?(url) end |
#read_configuration_file ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/rmega/cli.rb', line 29 def read_configuration_file return unless File.exists?(configuration_filepath) = YAML.load_file(configuration_filepath) .keys.each { |k| [k.to_sym] = .delete(k) } puts "Loaded configuration file #{configuration_filepath}" if [:debug] rescue Exception => ex raise(ex) if [:debug] end |
#traverse_storage(node, path, opts = {}) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/rmega/cli.rb', line 78 def traverse_storage(node, path, opts = {}) path.gsub!(/^\/|\/$/, "") curr_part = path.split("/")[0] || "" last_part = (path.split("/")[1..-1] || []).join("/") if curr_part.empty? if node.type == :root or node.type == :folder return node else return nil end else n = node.folders.find { |n| n.name.casecmp(curr_part).zero? } n ||= node.files.find { |n| n.name.casecmp(curr_part).zero? } unless opts[:only_folders] if last_part.empty? return n else return traverse_storage(n, last_part) end end end |