Class: BuildTool::Commands::Files

Inherits:
Standard show all
Defined in:
lib/build-tool/commands/files.rb

Overview

BuildCommand

Instance Attribute Summary

Attributes inherited from Base

#cmd, #options, #parent

Instance Method Summary collapse

Methods inherited from Standard

#complete_module, #complete_modules, #initialize, #log_directory, #while_logging_to

Methods inherited from Base

#<=>, #cleanup_after_vcs_access, #complete, #complete_arguments, #complete_readline_1_8, #complete_readline_1_9, #configuration, #do_complete_1_8, #do_complete_1_9, #each_option, #execute, #fullname, #initialize, #log?, #say, #setup_command, #show_help, #skip_command, #summarize, #teardown_command, #usage

Methods included from HelpText

#cmdalias, #description, included, #long_description, #name

Constructor Details

This class inherits a constructor from BuildTool::Commands::Standard

Instance Method Details

#applicable?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/build-tool/commands/files.rb', line 16

def applicable?
    BuildTool::Application.instance.has_recipe?
end

#do_execute(args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/build-tool/commands/files.rb', line 20

def do_execute( args )
    case args.length

    when 0
        return print_file_list

    when 1
        return print_file( args[0] )

    else
        return usage("Too many arguments.")

    end
end

#initialize_optionsObject



35
36
37
38
# File 'lib/build-tool/commands/files.rb', line 35

def initialize_options
    @options.banner = "Usage: #{Pathname.new($0).basename} #{self.fullname} [FILENAME]"
    super
end


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/build-tool/commands/files.rb', line 55

def print_file( filename )
    recipe = Application::instance.recipe
    files_dir = recipe.files_path
    if !files_dir.exist?
        say "No files supplied with this recipe"
        return 0
    end
    file = files_dir.join( filename )
    if !files_dir.exist?
        say "That file does not exist"
        return -1
    end

    erb = ERB.new( file.read, nil, "%<>" )
    b = binding
    settings = recipe.settings
    puts erb.result(b)
    return 0
end


40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/build-tool/commands/files.rb', line 40

def print_file_list
    recipe = Application::instance.recipe
    files_dir = recipe.files_path
    if !files_dir.exist?
        say "No files supplied with this recipe"
        return 0
    end
    Dir.new(files_dir).each do |entry|
        next if entry == "."
        next if entry == ".."
        say entry
    end
    return 0
end