Method: Milkode::Cdstk#dir

Defined in:
lib/milkode/cdstk/cdstk.rb

#dir(args, options) ⇒ Object



653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/milkode/cdstk/cdstk.rb', line 653

def dir(args, options)
  if args.empty?
    path = File.expand_path('.')
    package = @yaml.package_root(path)

    if (package)
      @out.print package.directory + (options[:top] ? "" : "\n")
    else
      # Use mcd.
      @out.print "Not registered." + (options[:top] ? "" : "\n")
    end
  else
    match_p = @yaml.contents.find_all do |p|
      args.all? {|k| p.name.include? k }
    end

    dirs = match_p.map{|v|v.directory}.reverse

    if options[:top]
      unless (dirs.empty?)
        @out.print dirs[0]
      else
        @out.print ""
      end
    else
      @out.puts dirs
    end
  end
end