06 Feb 2013, 20:14
Leo-1_pragsmall

Leonel Santos (11 posts)

This is just ONE example of several, I could say the same about the list and done commands.

According to the instructions on the book and the downloaded source code, this is what the new command is supposed to do (page 28 /be_easy_to_use/todo/bin/todo_integrated.rb).

desc ''
command :new do |c|

  c.flag :priority
  c.switch :f

  c.action do |global_options,options,args|
    puts "Global:"
    puts "-f - #{global_options[:f]}"
    puts "Command:"
    puts "-f - #{options[:f] ? 'true' : 'false'}"
    puts "-p - #{options[:p]}"
    puts "args - #{args.join(',')}"
  end
end

fast-forward to chapter 4 Play Well and this is what the new command is supposed to do (/play_well/todo/bin/todo)

desc 'Create a new task in the task list'
long_desc """
A task has a name and a priority. By default, new
tasks have the lowest possible priority, though
this can be overridden.
"""
arg_name 'task_name'
command :new do |c|

  c.desc 'set the priority of the new task, 1 being the highest'
  c.arg_name 'priority'
  c.flag :p

  c.desc 'put the new task first in the list'
  c.switch :f

  c.action do |global_options,options,args|
  end

I run the code I typed, I run the source code I downloaded, IT DOES NOT NOT NOT add any new items to ANY FILE.

What’s the deal here? Obviously the new command is not doing anything.

Are those commands NOT SUPPOSED TO work at this point? Is that the expected behavior?

Are we the readers SUPPOSED TO fill-in the blanks and figure out the code ourselves?

I thought this was supposed to be a tutorial-like, hands-on book; not a figure it out yourself book. Please let me know if I’m doing something wrong or if there are some mistakes in the book.

08 Feb 2013, 19:42
Dmfcb_pragsmall

David Copeland (98 posts)

What is being demonstrated is everything aside from the to-do list logic. The first example is showing you how to access the command line options at runtime, while the second example is showing you how to document your various commands and options. This isn’t relevant to actually making a todo list, and I didn’t want to get sidetracked with explaining how to open or append to files so as to make a working todo list.

I believe that the actual logic of a todo list (which would be the code that goes into the @action@ blocks of the various commands), should be a straightforward enough thing to add and make the examples into a real to-do list.

So, it is a tutorial for using GLI and related libraries, not on making a todo list or database backup app. You should hopefully be able to apply knowledge of GLI, OptionParser and friends to any particular problem.

  You must be logged in to comment