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_arguments, #complete_readline, #configuration, #debug, #debug2, #do_complete, #each_option, #error, #execute, #fullname, #info, #initialize, #log?, #setup_command, #setup_options, #show_help, #skip_command, #summarize, #teardown_command, #trace, #usage, #verbose, #warn

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)


18
19
20
# File 'lib/build-tool/commands/files.rb', line 18

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

#do_execute(args) ⇒ Object



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

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



37
38
39
40
41
42
# File 'lib/build-tool/commands/files.rb', line 37

def initialize_options
    options.banner = "Usage: #{self.fullname} [OPTIONS]... [FILENAME]"
    options.separator( "" )
    options.separator( "Options" )
    super
end


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/build-tool/commands/files.rb', line 59

def print_file( filename )
    recipe = Application::instance.recipe
    files_dir = recipe.files_path
    if !files_dir.exist?
        error( "No files supplied with this recipe" )
        return 0
    end
    file = files_dir.join( filename )
    if !file.exist?
        error( "File '#{filename}' not found! Found those:" )
        print_file_list
        return -1
    end

    erb = ERB.new( file.read, nil, "%<>" )
    b = binding
    settings = BuildTool::Application.instance.configuration.settings
    puts erb.result(b)
    return 0
end


44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/build-tool/commands/files.rb', line 44

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