Class: Strata::CLI::Generators::Project

Inherits:
Group
  • Object
show all
Includes:
API::ConnectionErrorHandler, API::ResponseErrorHandler
Defined in:
lib/strata/cli/generators/project.rb

Constant Summary collapse

BASE_SERVER_URL =
"http://localhost:3000"

Constants included from API::ResponseErrorHandler

API::ResponseErrorHandler::DETAIL_LIMIT

Constants included from Output

Output::THEME

Instance Method Summary collapse

Methods included from API::ConnectionErrorHandler

#with_connection_error_handling

Methods inherited from Group

exit_on_failure?, source_root

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

Instance Method Details

#completion_messageObject



128
129
130
131
132
133
134
135
# File 'lib/strata/cli/generators/project.rb', line 128

def completion_message
  Output.print_success("\n✔ Strata project '#{uid}' is ready!", context: self)
  Output.print_warning("\nNext steps:", context: self)
  Output.print_info("  1. cd #{uid}", context: self)
  Output.print_info("  2. strata datasource add      # To add more datasources", context: self)
  Output.print_info("  3. strata create table      # Start adding tables", context: self)
  Output.print_info("\n", context: self)
end

#create_agents_fileObject



85
86
87
88
89
# File 'lib/strata/cli/generators/project.rb', line 85

def create_agents_file
  return if cloned_from_git?

  copy_file "AGENTS.md", "#{uid}/AGENTS.md"
end

#create_datasources_fileObject



91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/strata/cli/generators/project.rb', line 91

def create_datasources_file
  return if cloned_from_git?

  template "datasources.yml", "#{uid}/datasources.yml"

  return unless options.key?(:datasource)

  options[:datasource].each do |ds|
    raise DWH::ConfigError, "Unsupported datasource #{ds}" unless DWH.adapter?(ds.to_sym)

    Datasource.new([ds.downcase.strip], options.merge({"path" => uid})).invoke_all
  end
end

#create_project_fileObject



69
70
71
72
73
# File 'lib/strata/cli/generators/project.rb', line 69

def create_project_file
  return if cloned_from_git?

  template "project.yml", "#{uid}/project.yml"
end

#create_project_structureObject



57
58
59
60
61
62
63
# File 'lib/strata/cli/generators/project.rb', line 57

def create_project_structure
  return if cloned_from_git?

  empty_directory uid
  empty_directory File.join(uid, "models")
  empty_directory File.join(uid, "tests")
end

#create_strata_config_fileObject



65
66
67
# File 'lib/strata/cli/generators/project.rb', line 65

def create_strata_config_file
  template "strata.yml", "#{uid}/.strata"
end

#fetch_and_clone_if_availableObject



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/strata/cli/generators/project.rb', line 44

def fetch_and_clone_if_available
  return unless options.key?(:source)

  project_info = fetch_project_info
  @project_id = project_info["id"]
  @project_info = project_info

  return unless project_info["git_url"] && !project_info["git_url"].empty?

  @cloned_from_git = true
  clone_project(project_info["git_url"])
end

#initialize_gitObject



105
106
107
108
109
110
111
112
# File 'lib/strata/cli/generators/project.rb', line 105

def initialize_git
  return if cloned_from_git?

  inside uid do
    run "git init", verbose: false, capture: true
    create_file ".gitignore", ".strata\n"
  end
end

#persist_project_id_if_neededObject



75
76
77
78
79
80
81
82
83
# File 'lib/strata/cli/generators/project.rb', line 75

def persist_project_id_if_needed
  # Persist project_id after project.yml exists (either from clone or creation)
  return unless @project_id

  project_yml_path = File.join(uid, "project.yml")
  return unless File.exist?(project_yml_path)

  persist_project_id_to_project_yml
end

#setup_datasourceObject



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/strata/cli/generators/project.rb', line 114

def setup_datasource
  return if cloned_from_git?
  return if options.key?(:datasource) # Already specified via CLI option

  print_status(:setup, "Let's configure your first datasource", type: :info)
  print_info("\n")

  # Change into the project directory and run the existing add command
  inside(uid) do
    require_relative "../sub_commands/datasource"
    SubCommands::Datasource.new.add
  end
end

#validate_optionsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/strata/cli/generators/project.rb', line 30

def validate_options
  if options.key?(:source)
    unless options.key?(:api_key)
      raise Strata::CommandError,
        "API key is required when using --source option. Use --api-key option."
    end
  else
    unless @name && !@name.to_s.strip.empty?
      raise Strata::CommandError,
        "PROJECT_NAME is required when not using --source option."
    end
  end
end