Class: Sakusei::CLI
- Inherits:
-
Thor
- Object
- Thor
- Sakusei::CLI
- Defined in:
- lib/sakusei/cli.rb
Class Method Summary collapse
-
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Override dispatch to treat file paths as build commands.
- .file_arg?(arg) ⇒ Boolean
-
.file_with_extension?(arg) ⇒ Boolean
Check if file exists with any of the supported markdown extensions.
Instance Method Summary collapse
- #build(*files) ⇒ Object
- #component(name) ⇒ Object
- #components(style = nil) ⇒ Object
- #concat(*files) ⇒ Object
- #init(name = 'default') ⇒ Object
- #preview(style = nil) ⇒ Object
- #set_style(name) ⇒ Object
- #styles ⇒ Object
- #version ⇒ Object
Class Method Details
.dispatch(meth, given_args, given_opts, config) ⇒ Object
Override dispatch to treat file paths as build commands
224 225 226 227 228 229 230 |
# File 'lib/sakusei/cli.rb', line 224 def self.dispatch(meth, given_args, given_opts, config) # If first arg is an existing file or glob pattern (and not a known subcommand), treat it as a build command if given_args.any? && !all_commands.key?(given_args.first) && file_arg?(given_args.first) given_args.unshift('build') end super end |
.file_arg?(arg) ⇒ Boolean
232 233 234 235 236 237 238 |
# File 'lib/sakusei/cli.rb', line 232 def self.file_arg?(arg) return false if arg.nil? return false if arg.start_with?('-') # Skip options # Check if it's a file (with or without extension), glob pattern, or directory File.exist?(arg) || file_with_extension?(arg) || arg.include?('*') || File.directory?(arg) end |
.file_with_extension?(arg) ⇒ Boolean
Check if file exists with any of the supported markdown extensions
241 242 243 244 245 246 |
# File 'lib/sakusei/cli.rb', line 241 def self.file_with_extension?(arg) return false if arg.nil? || arg.empty? return false if File.extname(arg).length > 0 # Already has an extension %w[.md .text .markdown].any? { |ext| File.exist?(arg + ext) } end |
Instance Method Details
#build(*files) ⇒ Object
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 |
# File 'lib/sakusei/cli.rb', line 27 def build(*files) raise Error, 'No input files provided' if files.empty? # Resolve file extensions (.md, .text, .markdown) if not provided resolved_files = files.map { |f| resolve_file_extension(f) } # Check if we have multiple files, globs, or directories if resolved_files.length > 1 || resolved_files.any? { |f| f.include?('*') || File.directory?(f) } # Multi-file build builder = MultiFileBuilder.new(resolved_files, ) else # Single file build raise Error, "File not found: #{resolved_files.first}" unless File.exist?(resolved_files.first) builder = Builder.new(resolved_files.first, ) end output_path = builder.build say "PDF created: #{output_path}", :green # Open the PDF if requested open_pdf(output_path) if [:open] rescue Error => e say_error e. exit 1 end |
#component(name) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 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 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/sakusei/cli.rb', line 144 def component(name) info = StylePack.find_component([:directory], name) unless info say_error "Component '#{name}' not found" exit 1 end say "\n" say "═" * 60, :cyan say " #{info[:name]}", :cyan say "═" * 60, :cyan say "\n" # Description if info[:description] say "📄 Description:" say " #{info[:description]}" say "\n" end # Location say "📁 Location:" say " #{info[:path]}", :cyan say " (in style pack: #{info[:pack_name]})" say "\n" # Props if info[:props]&.any? say "⚙️ Props:" info[:props].each do |prop| req_str = prop[:required] ? 'required' : 'optional' default_str = prop[:default] ? " (default: #{prop[:default]})" : "" type_str = prop[:type] ? " [#{prop[:type]}]" : "" say " • #{prop[:name]}#{type_str} - #{req_str}#{default_str}" end say "\n" end # Usage say "📝 Usage:" say " #{info[:usage]}", :green say "\n" # Full documentation if available if info[:full_description] && info[:full_description].lines.count > 1 say "📖 Documentation:" info[:full_description].lines.each do |line| say " #{line.rstrip}" end say "\n" end # Full source option if [:verbose] say "🔍 Template:" say info[:template] || "(no template)" say "\n" say "🔍 Script:" say info[:script] || "(no script)" say "\n" say "🔍 Style:" say info[:style] || "(no style)" else say "💡 Use --verbose to see the full component source code" end rescue Error => e say_error e. exit 1 end |
#components(style = nil) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/sakusei/cli.rb', line 108 def components(style = nil) pack = StylePack.discover([:directory], style) say "\nAvailable Vue components:\n\n" pack_components = pack.list_components if pack_components.any? say " Style pack: #{pack.name}", :cyan pack_components.each do |comp| desc_str = comp[:description] || '(no description)' say " • #{comp[:name].ljust(18)} #{desc_str}" end else say " Style pack '#{pack.name}' has no Vue components.", :yellow end if style.nil? local_components_dir = File.join(Dir.pwd, 'components') if Dir.exist?(local_components_dir) say "" say " Local (./components/)", :cyan Dir.glob(File.join(local_components_dir, '*.vue')).sort.each do |file| name = File.basename(file, '.vue') desc_str = StylePack.extract_docs_description(file) || '(no description)' say " • #{name.ljust(18)} #{desc_str}" end end end rescue Error => e say_error e. exit 1 end |
#concat(*files) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/sakusei/cli.rb', line 65 def concat(*files) raise Error, 'No input files provided' if files.empty? PdfConcatenator.new(files, [:output]).concat say "PDFs concatenated: #{[:output]}", :green rescue Error => e say_error e. exit 1 end |
#init(name = 'default') ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/sakusei/cli.rb', line 55 def init(name = 'default') StylePackInitializer.new([:directory], name).run say "Style pack '#{name}' created in #{[:directory]}/.sakusei/style_packs/#{name}", :green rescue Error => e say_error e. exit 1 end |
#preview(style = nil) ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/sakusei/cli.rb', line 11 def preview(style = nil) preview = StylePreview.new(style, ) output_path = preview.generate say "Style preview generated: #{output_path}", :green rescue Error => e say_error e. exit 1 end |
#set_style(name) ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/sakusei/cli.rb', line 98 def set_style(name) StylePack.set_default([:directory], name) say "Default style pack set to '#{name}'", :green rescue Error => e say_error e. exit 1 end |
#styles ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sakusei/cli.rb', line 77 def styles style_packs = StylePack.list_available([:directory]) if style_packs.empty? say 'No style packs found.', :yellow say "Run 'sakusei init <name>' to create a new style pack." else say 'Available style packs:', :green style_packs.each do |pack| label = pack[:default] ? " (default)" : '' say " • #{pack[:name]}#{label}" say " Path: #{pack[:path]}", :cyan end end rescue Error => e say_error e. exit 1 end |