Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require "file_utils"
- require "path"
- require "io/file_descriptor"
- require "option_parser"
- require "process"
- module Loon
- module Command
- class Cd
- private property options : Array(String)
- def initialize(@options : Array(String))
- end
- def run
- OptionParser.parse(options) do |parser|
- parser.banner = <<-STR
- Usage: loon cd [name with owner]
- Options:
- STR
- parser.on("-h", "--help", "Show this help") { Loon.ui.print parser }
- parser.unknown_args do |args|
- name_with_owner = args.shift
- repo = Loon::Git::Repository.from(name_with_owner)
- path = Config.current.resolve(repo)
- unless Dir.exists?(path)
- next Loon.ui.print "Path not found: #{path}"
- end
- IO::FileDescriptor.new(9) << "chdir:#{path}"
- rescue IO::Error
- # TODO(andremedeiros): Make this better
- Loon.ui.print "Error: Finalizer can't be written. Have you run me from the shell?"
- rescue IndexError
- Loon.ui.print parser
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment