Skip to content

Read options.default from anothe class? #60

@xbelanch

Description

@xbelanch

Maybe that's a dumb question, but firs of all take a look at this minimal working example:

#!/usr/bin/env ruby

module Minimal
    require 'rubygems'
    require 'commander/import'
    class CLI
        include Commander::Methods
        def self.parse(args)
            program :name, 'MWE'
            program :version, '0.0.1'
            program :description, 'Minimal Working Example'

            command :hello do |c|
                c.syntax = 'mwe hello'
                c.description =  'Say hello to everyone'
                c.option '--spanish', 'Say Hello in Spanish'
                c.option '--french', 'Say Hello in French'
                c.action do |args, options|
                    say options.default
                    options.default
                end
            end
        end
    end
end

module Minimal
    class Working
        def self.example(args)
            option = CLI.parse args
            if option.name = 'hello'
                #=> How can I check if spanish of french option is true?
            end
        end
    end
end

Minimal::Working.example ARGV

Well actually I'm trying to acces to options.default value outside the Commander space object, but I failed. What am I missing?

Thanks in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions