Class: Sxn::Commands::Projects
- Inherits:
-
Thor
- Object
- Thor
- Sxn::Commands::Projects
- Includes:
- Thor::Actions
- Defined in:
- lib/sxn/commands/projects.rb
Overview
Manage project configurations
Instance Method Summary collapse
- #add(name = nil, path = nil) ⇒ Object
- #info(name = nil) ⇒ Object
-
#initialize(args = ARGV, local_options = {}, config = {}) ⇒ Projects
constructor
A new instance of Projects.
- #list ⇒ Object
- #remove(name = nil) ⇒ Object
- #scan(base_path = nil) ⇒ Object
- #validate(name = nil) ⇒ Object
Constructor Details
#initialize(args = ARGV, local_options = {}, config = {}) ⇒ Projects
Returns a new instance of Projects.
11 12 13 14 15 16 17 18 |
# File 'lib/sxn/commands/projects.rb', line 11 def initialize(args = ARGV, = {}, config = {}) super @ui = Sxn::UI::Output.new @prompt = Sxn::UI::Prompt.new @table = Sxn::UI::Table.new @config_manager = Sxn::Core::ConfigManager.new @project_manager = Sxn::Core::ProjectManager.new(@config_manager) end |
Instance Method Details
#add(name = nil, path = nil) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/sxn/commands/projects.rb', line 25 def add(name = nil, path = nil) ensure_initialized! # Interactive mode if [:interactive] || name.nil? || path.nil? name ||= @prompt.project_name path ||= @prompt.project_path end begin @ui.progress_start("Adding project '#{name}'") project = @project_manager.add_project( name, path, type: [:type], default_branch: [:default_branch] ) @ui.progress_done @ui.success("Added project '#{name}'") display_project_info(project) rescue Sxn::Error => e @ui.progress_failed @ui.error(e.) exit(e.exit_code) rescue StandardError => e @ui.progress_failed @ui.error("Unexpected error: #{e.}") @ui.debug(e.backtrace.join("\n")) if ENV["SXN_DEBUG"] exit(1) end end |
#info(name = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/sxn/commands/projects.rb', line 199 def info(name = nil) ensure_initialized! if name.nil? projects = @project_manager.list_projects if projects.empty? @ui.empty_state("No projects configured") return end choices = projects.map { |p| { name: "#{p[:name]} (#{p[:type]})", value: p[:name] } } name = @prompt.select("Select project:", choices) end begin project = @project_manager.get_project(name) raise Sxn::ProjectNotFoundError, "Project '#{name}' not found" unless project @ui.section("Project Information: #{name}") display_project_info(project, detailed: true) # Show rules rules_manager = Sxn::Core::RulesManager.new(@config_manager, @project_manager) begin rules = rules_manager.list_rules(name) if rules.any? @ui.subsection("Rules") @table.rules(rules, name) else @ui.info("No rules configured for this project") end rescue StandardError => e @ui.debug("Could not load rules: #{e.}") end rescue Sxn::Error => e @ui.error(e.) exit(e.exit_code) end end |
#list ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sxn/commands/projects.rb', line 104 def list ensure_initialized! begin projects = @project_manager.list_projects @ui.section("Registered Projects") if projects.empty? @ui.empty_state("No projects configured") suggest_add_project elsif [:validate] list_with_validation(projects) else @table.projects(projects) @ui.newline @ui.info("Total: #{projects.size} projects") end rescue Sxn::Error => e @ui.error(e.) exit(e.exit_code) end end |
#remove(name = nil) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/sxn/commands/projects.rb', line 63 def remove(name = nil) ensure_initialized! # Interactive selection if name not provided if name.nil? projects = @project_manager.list_projects if projects.empty? @ui.empty_state("No projects configured") suggest_add_project return end choices = projects.map { |p| { name: "#{p[:name]} (#{p[:type]})", value: p[:name] } } name = @prompt.select("Select project to remove:", choices) end unless @prompt.confirm_deletion(name, "project") @ui.info("Cancelled") return end begin @ui.progress_start("Removing project '#{name}'") @project_manager.remove_project(name) @ui.progress_done @ui.success("Removed project '#{name}'") rescue Sxn::ProjectInUseError => e @ui.progress_failed @ui.error(e.) @ui.recovery_suggestion("Archive or remove the sessions first, or use --force") exit(e.exit_code) rescue Sxn::Error => e @ui.progress_failed @ui.error(e.) exit(e.exit_code) end end |
#scan(base_path = nil) ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/sxn/commands/projects.rb', line 132 def scan(base_path = nil) ensure_initialized! base_path ||= Dir.pwd begin @ui.progress_start("Scanning for projects in #{base_path}") detected = @project_manager.scan_projects(base_path) @ui.progress_done @ui.section("Detected Projects") if detected.empty? @ui.empty_state("No projects detected") return end display_detected_projects(detected) if [:register] register_projects(detected) elsif [:interactive] register_projects(detected) if @prompt.ask_yes_no("Register detected projects?", default: true) else @ui.info("Use --register to add these projects automatically") end rescue Sxn::Error => e @ui.error(e.) exit(e.exit_code) end end |
#validate(name = nil) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/sxn/commands/projects.rb', line 165 def validate(name = nil) ensure_initialized! if name.nil? projects = @project_manager.list_projects if projects.empty? @ui.empty_state("No projects configured") return end choices = projects.map { |p| { name: "#{p[:name]} (#{p[:type]})", value: p[:name] } } name = @prompt.select("Select project to validate:", choices) end begin result = @project_manager.validate_project(name) @ui.section("Project Validation: #{name}") if result[:valid] @ui.success("Project is valid") else @ui.error("Project has issues:") result[:issues].each { |issue| @ui.list_item(issue) } end display_project_info(result[:project]) rescue Sxn::Error => e @ui.error(e.) exit(e.exit_code) end end |