spaarti 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 42a2c8cb93c926b9c911da42d81fb138864905c1
4
- data.tar.gz: 919a5542bd9ec0de3f7c1058b8bf9e2b63ccf50b
3
+ metadata.gz: 60f66d0c8df26290e5fd5b9db40167d6e757f25b
4
+ data.tar.gz: 0f0cd166dc2e6b01a04bb6ad080a5dec07f0e392
5
5
  SHA512:
6
- metadata.gz: 6ce2e64fb7b01b27d98222d3a41959d3d610e6a44804ee9aff37c7a5434846e5653ad49dfb4f52743d22854eb9a3101ddd74b9c29af4e88a3f597056fb3cef7d
7
- data.tar.gz: 6e0deddbc39abf6881c08d02bbbb0d15184f14a0cc2d5d2dd8c88c930268bcbfe001abecd62241156e1357253338918a8b21fe18ef070055a4b2231b25cf1efc
6
+ metadata.gz: 9daab0358cfc4e3daab536e1b7c90f2b7d633c29df5b470ded1bf158960c1a5258728a628dfe45e745376767355e889dd43e50cb1ebd85829230dac2b531e8a3
7
+ data.tar.gz: 519a19ddb18f4347f2513fb73fe020c38684c7bb86f20dac5dd7aa26064687da3b734e443b5d9202dfa44483f9d1da6f5572811fdda35e9382e3a976a9dc26b9
@@ -8,7 +8,7 @@ Mercenary.program(:spaarti) do |p|
8
8
  p.description 'Tool for managing local checkouts of git repos'
9
9
  p.syntax 'spaarti [options]'
10
10
 
11
- p.option :config, '-c FILE', '--config FILE', 'Config file'
11
+ p.option :config_file, '-c FILE', '--config FILE', 'Config file'
12
12
  p.option :purge, '-p', '--purge', 'Remove orphaned repos'
13
13
  p.option :quiet, '-q', '--quiet', 'Silence standard output'
14
14
 
@@ -4,15 +4,15 @@ module Spaarti
4
4
  ##
5
5
  # Repo object, handles individual repo syncing and state
6
6
  class Repo
7
- def initialize(data, client, params)
8
- @raw = data
7
+ def initialize(data, client, params = {})
8
+ @data = data
9
9
  @client = client
10
- @params = params
11
- @path = @params[:format] % @raw
10
+ @options = params
11
+ @path = @options[:format] % @data
12
12
  end
13
13
 
14
14
  def sync!
15
- return log("#{@raw[:full_name]} already cloned") if Dir.exist?(@path)
15
+ return log("#{@data[:full_name]} already cloned") if Dir.exist?(@path)
16
16
  clone
17
17
  Dir.chdir(@path) { config && add_upstream }
18
18
  end
@@ -24,7 +24,7 @@ module Spaarti
24
24
  private
25
25
 
26
26
  def log(msg)
27
- puts msg unless @params[:quiet]
27
+ puts msg unless @options[:quiet]
28
28
  end
29
29
 
30
30
  def err(msg)
@@ -37,22 +37,22 @@ module Spaarti
37
37
  end
38
38
 
39
39
  def clone
40
- log "Cloning #{@raw[:ssh_url]} to #{@path}"
40
+ log "Cloning #{@data[:ssh_url]} to #{@path}"
41
41
  run(
42
- "git clone '#{@raw[:ssh_url]}' '#{@path}' &>/dev/null",
43
- "Failed to clone #{@raw[:ssh_url]}"
42
+ "git clone '#{@data[:ssh_url]}' '#{@path}' &>/dev/null",
43
+ "Failed to clone #{@data[:ssh_url]}"
44
44
  )
45
45
  end
46
46
 
47
47
  def config
48
- @params[:git_config].each do |k, v|
48
+ @options[:git_config].each do |k, v|
49
49
  run("git config '#{k}' '#{v}'", "Failed to set config for #{@path}")
50
50
  end
51
51
  end
52
52
 
53
53
  def add_upstream
54
- return unless @raw[:fork]
55
- upstream = @client.repo(@raw[:id]).source.git_url
54
+ return unless @data[:fork]
55
+ upstream = @client.repo(@data[:id]).source.git_url
56
56
  run(
57
57
  "git remote add upstream '#{upstream}'",
58
58
  "Failed to add upstrema for #{@path}"
@@ -6,29 +6,31 @@ require 'pathname'
6
6
  ##
7
7
  # Main Spaarti code, defines defaults and Site object
8
8
  module Spaarti
9
- DEFAULT_CONFIG_PATH = '~/.spaarti.yml'
10
-
11
- DEFAULT_CONFIG = {
9
+ DEFAULT_OPTIONS = {
12
10
  base_path: './',
13
11
  auth_file: :default,
12
+ config_file: File.expand_path('~/.spaarti.yml'),
14
13
  exclude: [],
15
14
  format: '%{full_name}',
16
- git_config: []
15
+ git_config: [],
16
+ quiet: false,
17
+ purge: false
17
18
  }
18
19
 
19
20
  ##
20
- # Site object, represents a group of repos with a config
21
+ # Site object, represents a group of repos
21
22
  class Site
22
- def initialize(options)
23
- @options = options
24
- if options[:config] && !File.exist?(options[:config])
25
- fail 'Config file does not exist'
23
+ def initialize(params = {})
24
+ if params[:config_file]
25
+ params[:config_file] = File.expand_path params[:config_file]
26
+ fail 'Conf file does not exist' unless File.exist? params[:config_file]
26
27
  end
27
- @options[:config] ||= DEFAULT_CONFIG_PATH
28
+ @options = DEFAULT_OPTIONS.dup.merge params
29
+ load_config
28
30
  end
29
31
 
30
32
  def sync!
31
- Dir.chdir(config[:base_path]) do
33
+ Dir.chdir(@options[:base_path]) do
32
34
  repos.each(&:sync!)
33
35
  purge! if @options[:purge]
34
36
  end
@@ -44,17 +46,10 @@ module Spaarti
44
46
 
45
47
  private
46
48
 
47
- def config
48
- @config ||= build_config
49
- end
50
-
51
- def build_config
52
- path = @options[:config]
53
- config = DEFAULT_CONFIG.dup
54
- return config unless File.exist?(path)
55
- file = File.open(path) { |fh| YAML.load fh.read }
56
- return nest if file.is_a? Array
57
- config.merge! Cymbal.symbolize(file)
49
+ def load_config
50
+ return unless File.exist?(@options[:config_file])
51
+ config = File.open(@options[:config_file]) { |fh| YAML.load fh.read }
52
+ @options.merge! Cymbal.symbolize(config)
58
53
  end
59
54
 
60
55
  def client
@@ -68,7 +63,7 @@ module Spaarti
68
63
  def auth
69
64
  @auth ||= Octoauth.new(
70
65
  note: 'spaarti',
71
- file: config[:auth_file],
66
+ file: @options[:auth_file],
72
67
  autosave: true
73
68
  )
74
69
  end
@@ -76,12 +71,12 @@ module Spaarti
76
71
  def repos
77
72
  @repos ||= client.repos.map do |data|
78
73
  next if excluded(data.name) || excluded(data.full_name)
79
- Repo.new data.to_h, client, config.subset(:format, :git_config)
74
+ Repo.new data.to_h, client, @options.subset(:format, :git_config)
80
75
  end
81
76
  end
82
77
 
83
78
  def excluded(string)
84
- config[:exclude].any? { |x| string.match(x) }
79
+ @options[:exclude].any? { |x| string.match(x) }
85
80
  end
86
81
  end
87
82
  end
@@ -1,5 +1,5 @@
1
1
  ##
2
2
  # Set the version (needed for Mercenary -v)
3
3
  module Spaarti
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spaarti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Aker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-06 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit