Class: WunderMarkdown::CLI
- Inherits:
-
Object
- Object
- WunderMarkdown::CLI
- Defined in:
- lib/wunder_markdown/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #call(args) ⇒ Object
- #client ⇒ Object
- #config(args, options) ⇒ Object
- #dump(args, options) ⇒ Object
- #group_tasks(tasks) ⇒ Object
- #preparse(args) ⇒ Object
- #token ⇒ Object
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
7 8 9 |
# File 'lib/wunder_markdown/cli.rb', line 7 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/wunder_markdown/cli.rb', line 7 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/wunder_markdown/cli.rb', line 7 def @options end |
Class Method Details
.run(args) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/wunder_markdown/cli.rb', line 9 def self.run(args) new.call(args) # rescue StandardError # $stderr.puts 'Woops, Something went wrong.' # exit 1 end |
Instance Method Details
#call(args) ⇒ Object
16 17 18 19 20 |
# File 'lib/wunder_markdown/cli.rb', line 16 def call(args) args, = preparse(args) command = args.shift public_send(command, args, ) end |
#client ⇒ Object
71 72 73 |
# File 'lib/wunder_markdown/cli.rb', line 71 def client @client ||= WunderMarkdown::Client.new(token) end |
#config(args, options) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/wunder_markdown/cli.rb', line 38 def config(args, ) $stdout.puts 'Wunderlist Credentials: We will not store your password' email = [:email] if ! email $stdout.puts 'email:' email = $stdin.gets.chomp end $stdout.puts 'Password:' system 'stty -echo' password = $stdin.gets.chomp system 'stty echo' WunderMarkdown::Auth.new.save(*client.login(email, password)) end |
#dump(args, options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wunder_markdown/cli.rb', line 52 def dump(args, ) list_name = args.shift unless list_name $stderr.puts 'Usage: wundermarkdown dump <list_name>' exit 1 end list = client.list(list_name) list.tasks = group_tasks(client.tasks(list)) $stdout.puts list.to_markdown end |
#group_tasks(tasks) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/wunder_markdown/cli.rb', line 63 def group_tasks(tasks) root_tasks = tasks.select { |task| task.root? } root_tasks.map do |task| task.children = tasks.select { |t| t.parent_id == task.id } task end end |
#preparse(args) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wunder_markdown/cli.rb', line 22 def preparse(args) = OpenStruct.new opt_parse = OptionParser.new do |opts| opts. = "Usage: wundermarkdown <command> <args> [options]" opts.on("-e EMAIL", "--email EMAIL", "Email address") do |email| .email = email end end opt_parse.parse!(args) unless args.count >= 1 $stderr.puts opt_parse exit 1 end [args, ] end |
#token ⇒ Object
75 76 77 |
# File 'lib/wunder_markdown/cli.rb', line 75 def token @token ||= WunderMarkdown::Auth.new.get end |