Sha256: 72d06375ad12f31b3ff62be761874f3b4f884314fb62b6ac8f547254f5bb7669

Contents?: true

Size: 1.51 KB

Versions: 36

Compression:

Stored size: 1.51 KB

Contents

#!/usr/bin/env ruby

require 'rbbt-util'
require 'rbbt/util/simpleopt'

$0 = "rbbt #{$previous_commands*" "} #{ File.basename(__FILE__) }" if $previous_commands

options = SOPT.setup <<EOF

Find a path

$ #{$0} [options] [<subpath>] <path>

Use - to read from STDIN

-h--help Print this help
-w--workflows Workflow to load
-s--search_path* Workflow to load
-l--list List contents of resolved directories
-n--nocolor Don't color output
EOF
if options[:help]
  if defined? rbbt_usage
    rbbt_usage 
  else
    puts SOPT.doc
  end
  exit 0
end

subpath, path = ARGV
path, subpath = subpath, nil if path.nil?

begin
  require 'rbbt/workflow'
  workflow = Workflow.require_workflow subpath
  subpath = workflow.libdir
rescue
  Log.exception $!
end if subpath && subpath =~ /^[A-Z][a-zA-Z]+$/

path = subpath ? Path.setup(subpath)[path] : Path.setup(path)

search_path = options[:search_path].to_sym if options.include? :search_path
nocolor = options[:nocolor]

found = if search_path
          [path.find(search_path)]
        else
          path.find_all
        end

found.each do |path|
  if options[:list] && File.directory?(path)
    puts Log.color :blue, path
    path.glob("*").each do |subpath|
      if nocolor
        puts subpath
      else
        color = File.directory?(subpath) ? :blue : nil
        puts " " << Log.color(color, subpath)
      end
    end
  else
    if nocolor
      puts path
    else
      color = File.exists?(path) ? (File.directory?(path) ? :blue : nil) : :red
      puts Log.color color, path
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
rbbt-util-5.34.10 bin/rbbt_find.rb
rbbt-util-5.34.9 bin/rbbt_find.rb
rbbt-util-5.34.8 bin/rbbt_find.rb
rbbt-util-5.34.7 bin/rbbt_find.rb
rbbt-util-5.34.5 bin/rbbt_find.rb
rbbt-util-5.34.4 bin/rbbt_find.rb
rbbt-util-5.34.3 bin/rbbt_find.rb
rbbt-util-5.34.2 bin/rbbt_find.rb
rbbt-util-5.34.1 bin/rbbt_find.rb
rbbt-util-5.34.0 bin/rbbt_find.rb
rbbt-util-5.33.21 bin/rbbt_find.rb
rbbt-util-5.33.20 bin/rbbt_find.rb
rbbt-util-5.33.19 bin/rbbt_find.rb
rbbt-util-5.33.18 bin/rbbt_find.rb
rbbt-util-5.33.17 bin/rbbt_find.rb
rbbt-util-5.33.16 bin/rbbt_find.rb
rbbt-util-5.33.15 bin/rbbt_find.rb
rbbt-util-5.33.14 bin/rbbt_find.rb
rbbt-util-5.33.13 bin/rbbt_find.rb
rbbt-util-5.33.12 bin/rbbt_find.rb