Guest User

Untitled

a guest
Jun 25th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. require "file_utils"
  2. require "path"
  3. require "io/file_descriptor"
  4. require "option_parser"
  5. require "process"
  6.  
  7. module Loon
  8. module Command
  9. class Cd
  10. private property options : Array(String)
  11.  
  12. def initialize(@options : Array(String))
  13. end
  14.  
  15. def run
  16. OptionParser.parse(options) do |parser|
  17. parser.banner = <<-STR
  18. Usage: loon cd [name with owner]
  19.  
  20. Options:
  21. STR
  22.  
  23. parser.on("-h", "--help", "Show this help") { Loon.ui.print parser }
  24.  
  25. parser.unknown_args do |args|
  26. name_with_owner = args.shift
  27. repo = Loon::Git::Repository.from(name_with_owner)
  28. path = Config.current.resolve(repo)
  29. unless Dir.exists?(path)
  30. next Loon.ui.print "Path not found: #{path}"
  31. end
  32. IO::FileDescriptor.new(9) << "chdir:#{path}"
  33. rescue IO::Error
  34. # TODO(andremedeiros): Make this better
  35. Loon.ui.print "Error: Finalizer can't be written. Have you run me from the shell?"
  36. rescue IndexError
  37. Loon.ui.print parser
  38. end
  39. end
  40. end
  41. end
  42. end
  43. end
Add Comment
Please, Sign In to add comment