Class: Strata::CLI::SubCommands::Project

Inherits:
Thor
  • Object
show all
Includes:
Guard, Output, Terminal
Defined in:
lib/strata/cli/sub_commands/project.rb

Constant Summary

Constants included from Output

Output::THEME

Constants included from Guard

Guard::ALLOWED_COMMANDS

Instance Method Summary collapse

Methods included from Output

format, pastel, print_error, #print_error, print_hint, #print_hint, print_info, #print_info, print_status, #print_status, print_success, #print_success, print_warning, #print_warning, shell_for, thor_color

Methods included from Terminal

#create_spinner, #print_table, #with_spinner

Methods included from Guard

#invoke_command

Instance Method Details



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/strata/cli/sub_commands/project.rb', line 19

def link(project_id)
  raise Strata::CommandError, "Project ID is required." unless project_id && !project_id.to_s.strip.empty?

  project_yml_path = "project.yml"
  project_config = YAML.safe_load_file(project_yml_path, permitted_classes: [Date, Time], aliases: true) || {}

  if project_config["project_id"] && !project_config["project_id"].to_s.strip.empty?
    print_warning("Project is already linked to project_id: #{project_config["project_id"]}")
    return
  end

  return unless Helpers::ProjectHelper.persist_project_id_to_yml(project_id, project_yml_path: project_yml_path)

  print_info("✓ Project linked successfully. project_id: #{project_id}")
end