Sha256: 789404d6a86563aae10072cbaa74a7c682897501df399ffcf0b5069db189e365

Contents?: true

Size: 1.67 KB

Versions: 4

Compression:

Stored size: 1.67 KB

Contents

#!/usr/bin/env ruby

require 's3repo'
require 'mercenary'
require 'yaml'
require 'cymbal'

def find(pattern, limits)
  Dir.glob(pattern).select { |x| !limits || limits.include?(File.dirname(x)) }
end

def common_opts(cmd)
  cmd.option :config_file, '-c', '--config FILE', 'Path of config file'
end

def load_config(file)
  file ||= 'config.yml'
  file = File.expand_path(file)
  raise("Config file not found: #{file}") unless File.exist? file
  Cymbal.symbolize YAML.safe_load(File.read(file))
end

def repo(options)
  config = load_config(options[:config_file])
  S3Repo.new(config)
end

# rubocop:disable Metrics/BlockLength
Mercenary.program(:s3repo) do |p|
  p.version S3Repo::VERSION
  p.description 'Package management tool for Archlinux repos'
  p.syntax 's3repo <subcommand> [args]'

  p.command(:build) do |c|
    common_opts(c)
    c.syntax 'build [package...]'
    c.description 'Build package files from PKGBUILDs'

    c.action do |args, opts|
      repo(opts).build_packages find('*/PKGBUILD', args)
    end
  end

  p.command(:upload) do |c|
    common_opts(c)
    c.syntax 'upload [package...]'
    c.description 'Upload packages to repo'

    c.action do |args, opts|
      repo(opts).add_packages find('*/*.pkg.tar.xz', args)
    end
  end

  p.command(:remove) do |c|
    common_opts(c)
    c.syntax 'remove [package...]'
    c.description 'Remove packages from repo DB'

    c.action do |args, opts|
      repo(opts).remove_packages args
    end
  end

  p.command(:prune) do |c|
    common_opts(c)
    c.syntax 'prune'
    c.description 'Prune orphaned files from the repo'

    c.action do |_, opts|
      repo(opts).prune_files
    end
  end

  p.action do
    puts p
    exit 1
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
s3repo-2.0.3 bin/s3repo
s3repo-2.0.2 bin/s3repo
s3repo-2.0.1 bin/s3repo
s3repo-2.0.0 bin/s3repo