Module: GitStyleBinary

Extended by:
Helpers::NameResolver
Defined in:
lib/git-style-binary.rb,
lib/git-style-binary/parser.rb,
lib/git-style-binary/command.rb,
lib/git-style-binary/autorunner.rb,
lib/git-style-binary/commands/help.rb,
lib/git-style-binary/helpers/pager.rb,
lib/git-style-binary/helpers/name_resolver.rb

Defined Under Namespace

Modules: Commands, Helpers Classes: AutoRunner, Command, Parser, Primary

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Helpers::NameResolver

basename, binary_directory, binary_filename_for, built_in_command_names, built_in_commands_directory, current_command_name, full_current_command_name, list_subcommands, pretty_known_subcommands, subcommand_names, valid_subcommand?, zero

Class Attribute Details

.current_commandObject

Returns the value of attribute current_command.



14
15
16
# File 'lib/git-style-binary.rb', line 14

def current_command
  @current_command
end

.known_commandsObject



30
31
32
# File 'lib/git-style-binary.rb', line 30

def known_commands
  @known_commands ||= {}
end

.name_of_command_being_loadedObject

UGLY eek



65
66
67
# File 'lib/git-style-binary.rb', line 65

def name_of_command_being_loaded
  @name_of_command_being_loaded
end

.primary_commandObject

Returns the value of attribute primary_command.



15
16
17
# File 'lib/git-style-binary.rb', line 15

def primary_command
  @primary_command
end

.run=(value) ⇒ Object (writeonly)

If set to false GitStyleBinary will not automatically run at exit.



19
20
21
# File 'lib/git-style-binary.rb', line 19

def run=(value)
  @run = value
end

Class Method Details

.command(&block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/git-style-binary/command.rb', line 5

def self.command(&block)
  Command.new(:constraints => [block]).tap do |c|
    c.name ||= (GitStyleBinary.name_of_command_being_loaded ||
                GitStyleBinary.current_command_name)
    GitStyleBinary.known_commands[c.name] = c

    if !GitStyleBinary.current_command ||
        GitStyleBinary.current_command.is_primary?
      GitStyleBinary.current_command = c
    end
  end
end

.load_command_file(name, file) ⇒ Object



58
59
60
61
62
# File 'lib/git-style-binary.rb', line 58

def load_command_file(name, file)
  self.name_of_command_being_loaded = name
  load file
  self.name_of_command_being_loaded = nil
end

.load_primaryObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/git-style-binary.rb', line 34

def load_primary
  unless @loaded_primary
    @loaded_primary = true
    primary_file = File.join(binary_directory, basename)
    load primary_file

    if !GitStyleBinary.primary_command # you still dont have a primary load a default
      GitStyleBinary.primary do
        run do |command|
          educate
        end
      end
    end
  end
end

.load_subcommandObject



50
51
52
53
54
55
56
# File 'lib/git-style-binary.rb', line 50

def load_subcommand
  unless @loaded_subcommand
    @loaded_subcommand = true
    cmd_file = GitStyleBinary.binary_filename_for(GitStyleBinary.current_command_name)
    load cmd_file
  end
end

.parserObject



26
27
28
# File 'lib/git-style-binary.rb', line 26

def parser
  @p ||= Parser.new
end

.primary(&block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/git-style-binary/command.rb', line 18

def self.primary(&block)
  Primary.new(:constraints => [block]).tap do |c|
    c.name ||= (GitStyleBinary.name_of_command_being_loaded ||
                GitStyleBinary.current_command_name)
    GitStyleBinary.known_commands[c.name] = c

    GitStyleBinary.primary_command = c unless GitStyleBinary.primary_command
    GitStyleBinary.current_command = c unless GitStyleBinary.current_command
  end
end

.run?Boolean

Automatically run at exit?

Returns:

  • (Boolean)


22
23
24
# File 'lib/git-style-binary.rb', line 22

def run?
  @run ||= false
end