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.



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

def current_command
  @current_command
end

.known_commandsObject



43
44
45
# File 'lib/git-style-binary.rb', line 43

def known_commands
  @known_commands ||= {}
end

.name_of_command_being_loadedObject

UGLY eek



78
79
80
# File 'lib/git-style-binary.rb', line 78

def name_of_command_being_loaded
  @name_of_command_being_loaded
end

.primary_commandObject

Returns the value of attribute primary_command.



28
29
30
# File 'lib/git-style-binary.rb', line 28

def primary_command
  @primary_command
end

.run=(value) ⇒ Object (writeonly)

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



32
33
34
# File 'lib/git-style-binary.rb', line 32

def run=(value)
  @run = value
end

Class Method Details

.command(&block) ⇒ Object



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

def self.command(&block)
  returning Command.new(:constraints => [block]) 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



71
72
73
74
75
# File 'lib/git-style-binary.rb', line 71

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/git-style-binary.rb', line 47

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



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

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



39
40
41
# File 'lib/git-style-binary.rb', line 39

def parser
  @p ||= Parser.new
end

.primary(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/git-style-binary/command.rb', line 15

def self.primary(&block)
  returning Primary.new(:constraints => [block]) 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)


35
36
37
# File 'lib/git-style-binary.rb', line 35

def run?
  @run ||= false
end