Class: Stable::Commands::Workdir
- Inherits:
-
Object
- Object
- Stable::Commands::Workdir
- Defined in:
- lib/stable/commands/workdir.rb
Overview
Open App’s work director
Constant Summary collapse
- EDITOR_COMMANDS =
{ 'vscode' => 'code', 'sublime' => 'subl', 'atom' => 'atom' }.freeze
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(app_name, editor) ⇒ Workdir
constructor
A new instance of Workdir.
Constructor Details
#initialize(app_name, editor) ⇒ Workdir
Returns a new instance of Workdir.
13 14 15 16 |
# File 'lib/stable/commands/workdir.rb', line 13 def initialize(app_name, editor) @app_name = app_name @editor = editor.downcase end |
Instance Method Details
#call ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/stable/commands/workdir.rb', line 18 def call app = Services::AppRegistry.find(@app_name) abort "App '#{@app_name}' not found" unless app abort "App path does not exist: #{app[:path]}" unless Dir.exist?(app[:path]) editor_cmd = EDITOR_COMMANDS[@editor] || @editor # support custom editors unless system("which #{editor_cmd} > /dev/null 2>&1") abort "Editor command not found: #{editor_cmd}" end puts "🚀 Opening #{@app_name} in #{@editor}..." system("#{editor_cmd} #{app[:path]}") end |