Module: SpaceArchitect::CLI::Helpers
- Included in:
- Architect::Dispatch, Architect::Freeze, Architect::Init, Architect::New, Architect::Status, Architect::Variant::Add, Architect::Variant::Compare, Architect::Variant::Promote, Architect::Verify, Architect::Worktree::Add, Architect::Worktree::List, Architect::Worktree::Remove, Config::ConfigPath, Config::Set, Config::Show, Current, Init, List, New, Path, Repo::Add, Repo::RepoList, Repo::Resolve, Shell::Complete, Shell::Fish, Shell::ShellInit, Show, Status, Use
- Defined in:
- lib/space_architect/cli/helpers.rb
Instance Method Summary collapse
- #display_date(space) ⇒ Object
- #handle_errors ⇒ Object
- #project_config ⇒ Object
- #render(result) ⇒ Object
- #setup_terminal(color: "auto", colors: nil) ⇒ Object
- #state ⇒ Object
- #store ⇒ Object
- #terminal ⇒ Object
Instance Method Details
#display_date(space) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/space_architect/cli/helpers.rb', line 34 def display_date(space) id_date = space.id.match(/\A(\d{4})(\d{2})(\d{2})/) return "#{id_date[1]}-#{id_date[2]}-#{id_date[3]}" if id_date space.data["created_at"].to_s[0, 10] end |
#handle_errors ⇒ Object
41 42 43 44 45 46 47 48 49 50 |
# File 'lib/space_architect/cli/helpers.rb', line 41 def handle_errors yield rescue SpaceArchitect::Error => e if terminal terminal.error(e.) else err.puts e. end CLI.record_outcome(Outcome.new(exit_code: 1, message: e.)) end |
#project_config ⇒ Object
9 10 11 |
# File 'lib/space_architect/cli/helpers.rb', line 9 def project_config @project_config ||= SpaceArchitect::Config.load end |
#render(result) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/space_architect/cli/helpers.rb', line 52 def render(result) case result when Dry::Monads::Result::Success yield result.value! if block_given? when Dry::Monads::Result::Failure error = result.failure = error.respond_to?(:message) ? error. : error.to_s terminal ? terminal.error() : err.puts() CLI.record_outcome(Outcome.new(exit_code: 1, message: )) end end |
#setup_terminal(color: "auto", colors: nil) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/space_architect/cli/helpers.rb', line 25 def setup_terminal(color: "auto", colors: nil) @terminal = Terminal.new( config: project_config, stdout: out, stderr: err, color_mode: colors || color || "auto" ) end |
#state ⇒ Object
13 14 15 |
# File 'lib/space_architect/cli/helpers.rb', line 13 def state @state ||= SpaceArchitect::State.load end |
#store ⇒ Object
17 18 19 |
# File 'lib/space_architect/cli/helpers.rb', line 17 def store @store ||= SpaceArchitect::SpaceStore.new(config: project_config, state: state) end |
#terminal ⇒ Object
21 22 23 |
# File 'lib/space_architect/cli/helpers.rb', line 21 def terminal @terminal end |