Class: RepoManager::ListAction

Inherits:
AppAction show all
Includes:
ActionHelper
Defined in:
lib/repo_manager/actions/list_action.rb

Overview

List assets to the screen or file with or without templates using regular expression (regex) filtering.

Examples:

Usage: repo list


repo list
repo list --list=NAME
repo list --type=asset_type
repo list --template ~/templates/myTemplate.slim

Asset regex filtering:


repo list --filter=ass.t1,as.et2

Equivalent asset filtering:


repo list --filter=asset1,asset2
repo list --asset=asset1,asset2
repo list asset1 asset2

Equivalent usage, file writing:


repo list --template=default.slim --output=tmp/aruba/index.html
repo list --template=default.slim >> tmp/aruba/index.html

return just the first matching asset


repo list --match=FIRST

Fail out if more than one matching asset


repo list --match=ONE

Disable regex filter matching


repo list --match=EXACT

Future usage (not implemented):


repo list --tags=adventure,favorites --group_by=tags --sort=ACQUIRED

Create a Bash ‘alias’ named ‘rcd’ to chdir to the folder of the repo


function rcd(){ cd "$(repo --match=ONE --no-color path $@)"; }

rcd my_repo_name

Repo versions of Bash’s pushd and popd


function rpushd(){ pushd "$(repo path --match=ONE --no-color $@)"; }
alias rpopd="popd"

rcd my_repo_name

Returns:

  • (Number)

    0 if successful

Instance Attribute Summary

Attributes inherited from BaseAction

#args, #configuration, #exit_code, #option_parser, #options, #output, #template

CLI actions collapse

Methods included from ActionHelper

#relative_path, #shell_quote, #windows?

Methods inherited from AppAction

#asset_type, #repos

Methods inherited from BaseAction

#after_execute, #asset_options, #asset_type, #assets, #before_execute, #execute, #initialize, #items, #overwrite_output?, #process, #write_to_output

Constructor Details

This class inherits a constructor from RepoManager::BaseAction

Instance Method Details

#helpObject



118
119
120
# File 'lib/repo_manager/actions/list_action.rb', line 118

def help
  super :comment_starting_with => "List assets", :located_in_file => __FILE__
end

#parse_optionsObject

Add action specific options



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/repo_manager/actions/list_action.rb', line 67

def parse_options
  super do |opts|

    opts.on("--list MODE", "Listing mode.  ALL, NAME, SHORT, PATH") do |u|
      options[:list] = u
      options[:list].upcase!
      unless ["ALL", "NAME", "SHORT", "PATH"].include?(options[:list])
        raise "invalid list mode '#{options[:list]}' for '--list' option"
      end
    end

    opts.on("--short", "List summary status only, alias for '--list=SHORT'") do |s|
      options[:list] = 'SHORT'
    end

    # Most decendants of BaseAction will only handle one type of asset, the
    # list action is unique in that you can specify the type of asset to list
    opts.on("--type ASSET_TYPE", "Asset type to list:  app_asset (default)") do |t|
      options[:type] = t
      unless ["app_asset"].include?(options[:type])
        raise "unknown asset type '#{options[:type]}' for '--type' option"
      end
    end

  end
end

#render(view_options = configuration) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/repo_manager/actions/list_action.rb', line 94

def render(view_options=configuration)
  # templates override all other modes, if no mode specified, allow super to handle
  list_mode = options[:template] || options[:list]
  result = ""
  case list_mode
    when 'NAME'
      items.each do |item|
        result += "#{item.name.green}\n"
      end
    when 'SHORT'
      items.each do |item|
        result += item.name.green
        result += ": #{relative_path(item.path)}\n"
      end
    when 'PATH'
      items.each do |item|
        result += "#{item.path}\n"
      end
    else
      result = super(view_options)
  end
  result
end