class Bashly::Commands::Add

Attributes

skip_src_check[R]

Public Instance Methods

run() click to toggle source
# File lib/bashly/commands/add.rb, line 23
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

add_lib(name) click to toggle source
# File lib/bashly/commands/add.rb, line 55
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
add_library_files(library) click to toggle source
# File lib/bashly/commands/add.rb, line 65
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
  say "\n#{message}" if message && files_created.positive?
end
lib_source() click to toggle source
# File lib/bashly/commands/add.rb, line 41
def lib_source
  @lib_source ||= Bashly::LibrarySource.new source
end
safe_write(path, content) click to toggle source
# File lib/bashly/commands/add.rb, line 76
      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
show_list() click to toggle source
# File lib/bashly/commands/add.rb, line 45
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
source() click to toggle source
# File lib/bashly/commands/add.rb, line 37
def source
  args['--source']
end