class Bashly::Commands::Add
Attributes
Public Instance Methods
Source
# File lib/bashly/commands/add.rb, line 24 def run say "Performing git operations, this may take a while...\n" if lib_source.git? if args['--list'] show_list else add_lib args['LIBRARY'] end lib_source.cleanup if lib_source.git? end
Private Instance Methods
Source
# File lib/bashly/commands/add.rb, line 56 def add_lib(name) library = lib_source.libraries[name.to_sym] raise "Unknown library: g`#{name}`\nRun m`bashly add --list` to see available libraries" unless library library.args = args['ARGS'] @skip_src_check = lib_source.config.dig name, 'skip_src_check' add_library_files library end
Source
# File lib/bashly/commands/add.rb, line 66 def add_library_files(library) files_created = 0 library.files.each do |file| created = safe_write file[:path], file[:content] files_created += 1 if created end message = library.post_install_message return if !message || files_created.zero? || args['--quiet'] say "\n#{message}" end
Source
# File lib/bashly/commands/add.rb, line 42 def lib_source @lib_source ||= Bashly::LibrarySource.new source end
Source
# File lib/bashly/commands/add.rb, line 79 def safe_write(path, content) if !skip_src_check && !Dir.exist?(Settings.source_dir) raise InitError, <<~ERROR Directory g`#{Settings.source_dir}` does not exist Run m`bashly init` first ERROR end if File.exist?(path) && !args['--force'] say "b`skipped` #{path} (exists)" false else File.deep_write path, content say "g`created` #{path}" true end end
Source
# File lib/bashly/commands/add.rb, line 46 def show_list lib_source.config.each do |key, config| usage = key usage += " #{config['usage']}" if config['usage'] say "g`#{usage}`" say word_wrap(" #{config['help']}") say '' end end