repomap 0.0.1 → 0.0.10

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.
data/.gitignore CHANGED
@@ -1,2 +1,4 @@
1
1
  *.gem
2
2
  tmp
3
+ Gemfile.lock
4
+ *.swp
data/README.md CHANGED
@@ -1,11 +1,6 @@
1
1
  # RepoMap
2
2
 
3
- Keep track of your git repos.
4
-
5
- Want all git repos in some directory to be listed in one place?
6
-
7
- - `repo add -r [directory holding repositories]`
8
- - `repo ls`
3
+ Keep track of your local git repos.
9
4
 
10
5
  Add and remove any git repository to RepoMap, and it will keep
11
6
  track of them in a simple YAML file. You can also pretty print
@@ -13,8 +8,20 @@ your git repositories.
13
8
 
14
9
  CLI:
15
10
  - `repo ls`
16
- - `repo add [-r for recursive] [git repo path]`
11
+ - `repo add [optional: -r for recursive] [git repo path]`
17
12
  - `repo rm [git repo path]`
13
+ - `repo find [optional: path/to/search] [regex pattern, like ".*"]`
14
+
15
+ Want all git repos in some directory to be listed in one place?
16
+
17
+ - `repo add -r [directory holding repositories]`
18
+ - `repo ls`
19
+
20
+ Want to search with regular expressions for a repo within RepoMap?
21
+
22
+ - `repo find "test[0-9]{1}"`
23
+ - `repo find ~/devel/Ruby "test[0-9]{1}"`
24
+
18
25
 
19
26
  ## Installation
20
27
 
@@ -23,6 +30,14 @@ affect the state of one file that it itself creates, it's actually OK to use
23
30
  already. Check out the specs in `spec` and the source in `lib` if you wanna see
24
31
  what's happening.
25
32
 
33
+ ### Install from RubyGems
34
+
35
+ - `gem install repomap`
36
+
37
+ On first use, `~/.repomap.yml` will be created.
38
+
39
+ ### Build from Gemspec
40
+
26
41
  - `gem build repomap.gemspec`
27
42
  - `gem install repomap-x.x.x.gem`
28
43
 
@@ -38,13 +53,15 @@ On first use, `~/.repomap.yml` will be created.
38
53
 
39
54
  **Sub Commands**
40
55
 
41
- - add [path to git repository]
42
- - Add the given git repository to RepoMan
56
+ - `add [optional: -r] [path to git repository]`
57
+ - Add the given git repository to RepoMap
43
58
  - Use `-r` switch to add all git repository under some path
44
- - rm [path to git repository]
45
- - Add the given git repository to RepoMan
46
- - ls
47
- - List all git repositories in RepoMan
59
+ - `rm [path to git repository]`
60
+ - Add the given git repository to RepoMap
61
+ - `ls`
62
+ - List all git repositories in RepoMap
63
+ - `find [optional: path/to/search] [regex pattern, like ".*"]`
64
+ - Find a repo in RepoMap
48
65
 
49
66
  ## Testing
50
67
 
@@ -55,9 +72,9 @@ On first use, `~/.repomap.yml` will be created.
55
72
  - ~~search a given path recusively for all git repos, adding any that
56
73
  are found to RepoMan~~
57
74
  - ~~make a gemspec~~
58
- - add some simple specs
59
- - added specs for `#add!`
75
+ - ~~add some simple specs~~
60
76
  - ~~change name because of conflicts with other gem names~~
77
+ - ~~add a find command~~
61
78
  - an 'update' command to update information about each repo that RepoMan
62
79
  knows about
63
80
  - keep track of other meta data about git repos (remotes, for instance)
data/bin/repo CHANGED
@@ -46,32 +46,56 @@ subcommands = {
46
46
  STDOUT.puts opts
47
47
  exit 0
48
48
  end
49
+ end,
50
+ 'find' => OptionParser.new do |opts|
51
+ opts.banner = "Usage: find [optional: where to search] [regex pattern, like \".*\"]"
52
+ opts.on("-h", "--help", "Display this screen") do
53
+ STDOUT.puts opts
54
+ exit 0
55
+ end
49
56
  end
50
57
  }
51
58
 
52
59
  begin
53
60
  global.order!
54
-
55
61
  argv_minus_global_opts = ARGV.dup
56
-
57
62
  subcommands[ARGV.shift].order!
58
63
  subcommand = argv_minus_global_opts.shift
59
-
60
- if ((subcommand =~ /add/)==0)
64
+
65
+ case subcommand
66
+ when /add/
61
67
  if argv_minus_global_opts.length >= 1
62
- add_opts[:add] = argv_minus_global_opts[-1]
63
- RepoMap.handle(add_opts)
68
+ opts = {:action => :add}
69
+ opts[:options] = {:path => argv_minus_global_opts[-1],
70
+ :recursive => add_opts[:recursive]}
71
+ RepoMap.handle(opts)
64
72
  end
65
- end
66
-
67
- if ((subcommand =~ /rm/)==0)
73
+ when /rm/
68
74
  if argv_minus_global_opts.length==1
69
- path = argv_minus_global_opts.shift
70
- RepoMap.handle(:remove=>path)
75
+ opts = {:action => :remove}
76
+ opts[:options] = {:path => argv_minus_global_opts.shift}
77
+ RepoMap.handle(opts)
71
78
  end
72
- end
73
-
74
- RepoMap.handle(:list=>true) if ((subcommand =~ /ls/)==0)
79
+ when /ls/
80
+ if argv_minus_global_opts.length==0
81
+ opts = {:action => :list}
82
+ RepoMap.handle(opts)
83
+ end
84
+ when /find/
85
+ opts = {:action => :find}
86
+ if argv_minus_global_opts.length==2
87
+ opts[:options] = {:path => argv_minus_global_opts[0],
88
+ :pattern => argv_minus_global_opts[1]}
89
+ RepoMap.handle(opts)
90
+ end
91
+ if argv_minus_global_opts.length==1
92
+ opts[:options] = {:path => nil,
93
+ :pattern => argv_minus_global_opts.shift}
94
+ RepoMap.handle(opts)
95
+ end
96
+ else
97
+ puts "repo: Not a known subcommand"
98
+ end
75
99
 
76
100
  exit 0
77
101
  rescue OptionParser::MissingArgument => e
data/lib/repomap.rb CHANGED
@@ -5,23 +5,54 @@ require 'repomap/version'
5
5
  require 'repomap/add'
6
6
  require 'repomap/remove'
7
7
  require 'repomap/list'
8
+ require 'repomap/find'
8
9
 
9
10
  module RepoMap
10
11
 
11
12
  # receive a hashmap like:
12
- # {:add => 'path/to/repo/or/dir',
13
- # :recursive => bool}, or
14
- # {:list => bool}, or
15
- # {:remove => 'path/to/repo/in/repomap'}
13
+ #
14
+ # {:action => :add,
15
+ # :options => {:recursive => false}}, or
16
+ # {:action => :remove,
17
+ # :options => {:path => some/path }}, or
18
+ # {:action => :list,
19
+ # :options => nil}, or
20
+ # {:action => :find,
21
+ # :opions => {:path => some/path,
22
+ # :pattern => "some regex"}}
23
+ #
16
24
  # Then, call appropriate functions.
17
25
  def self.handle options
18
- if options[:add] != '' and options[:add] != nil and options[:recursive]==true
19
- add_recursive! options[:add]
20
- elsif options[:add] != '' and options[:add] != nil and options[:recursive]==false
21
- add! options[:add]
26
+
27
+ case options[:action].to_s
28
+ when /add/
29
+ if path_exists? options
30
+ add_recursive! options[:options][:path] if options[:options][:recursive]
31
+ add! options[:options][:path] if not options[:options][:recursive]
32
+ end
33
+ when /remove/
34
+ if path_exists? options
35
+ remove! options[:options][:path]
36
+ end
37
+ when /list/
38
+ list
39
+ when /find/
40
+ path = options[:options][:path]
41
+ pattern = options[:options][:pattern]
42
+ find path, pattern
22
43
  end
23
- remove! options[:remove] if options[:remove] != '' and options[:remove] != nil
24
- list if options[:list]
44
+
45
+ end
46
+
47
+ def path_exists? options
48
+
49
+ if options[:options][:path] != nil and
50
+ options[:options][:path] != ''
51
+ return true
52
+ else
53
+ return false
54
+ end
55
+
25
56
  end
26
57
 
27
58
  end
@@ -0,0 +1,38 @@
1
+ module RepoMap
2
+
3
+ def find path, pattern
4
+ if path
5
+ find_with_path path, pattern
6
+ else
7
+ find_without_path pattern
8
+ end
9
+ end
10
+
11
+ def find_with_path path, pattern
12
+ repo_map_validate
13
+ hash = YAML::load(File.read(repo_map))
14
+ regex = Regexp.new(pattern)
15
+ fp = File.expand_path(path)
16
+ fp_reg = Regexp.new(fp)
17
+ hash.each do |k, v|
18
+ fk = File.expand_path(k.to_s)
19
+ m = fk.match(fp_reg)
20
+ is_subdir = (fk.length>fp.length)&&(m.to_s==fp)
21
+ if is_subdir and v[:name].to_s.match(regex)!=nil
22
+ puts k.to_s
23
+ end
24
+ end
25
+ end
26
+
27
+ def find_without_path pattern
28
+ repo_map_validate
29
+ hash = YAML::load(File.read(repo_map))
30
+ regex = Regexp.new pattern
31
+ hash.each do |k, v|
32
+ if v[:name].to_s.match(regex)!=nil
33
+ puts k.to_s
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -15,7 +15,6 @@ module RepoMap
15
15
  File.open(repo_map, "w") do |f|
16
16
  f.write hash.to_yaml
17
17
  end
18
- exit 0
19
18
  end
20
19
 
21
20
  end
@@ -1,3 +1,3 @@
1
1
  module RepoMap
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.10'
3
3
  end
data/spec/repoman_spec.rb CHANGED
@@ -21,21 +21,47 @@ describe "RepoMap SubCommands" do
21
21
  end
22
22
 
23
23
  after :each do
24
- rm_f "#{REPO1}/.git"
24
+ rm_rf "#{REPO1}/.git"
25
25
  end
26
26
 
27
27
  after :all do
28
- `rm -rf "#{File.dirname(__FILE__)}/../tmp"`
28
+ rm_rf "#{File.dirname(__FILE__)}/../tmp"
29
29
  end
30
30
 
31
31
  describe "#add!" do
32
32
 
33
33
  it "should add a given path to ENV['REPO_MAP']" do
34
- RepoMap.handle :add => REPO1, :recursive => false
34
+ opts = repo_opts :add, REPO1
35
+ RepoMap.handle(opts)
35
36
  hash = YAML::load(File.read(repo_map))
36
37
  hash[File.expand_path(REPO1).to_sym][:name].should == File.basename(REPO1)
37
38
  end
38
39
 
39
40
  end
40
41
 
42
+ describe "#remove!" do
43
+
44
+ it "should remove a given path from ENV['REPO_MAP']" do
45
+ opts = repo_opts :add, REPO1
46
+ RepoMap.handle opts
47
+ hash1 = YAML::load(File.read(repo_map))
48
+ repo1_in_repomap = hash1[File.expand_path(REPO1).to_sym][:name] \
49
+ == File.basename(REPO1)
50
+ opts = repo_opts :remove, REPO1
51
+ RepoMap.handle opts
52
+ hash2 = YAML::load(File.read(repo_map))
53
+ repo1_removed = !(hash2.has_key?(File.expand_path(REPO1).to_sym))
54
+ (repo1_in_repomap and repo1_removed).should == true
55
+ end
56
+
57
+ end
58
+
59
+ end
60
+
61
+ def repo_opts action, repo_path
62
+ opts = {}
63
+ opts[:action] = action
64
+ opts[:options] = {:path => repo_path,
65
+ :recursive => false}
66
+ return opts
41
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repomap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-18 00:00:00.000000000 Z
12
+ date: 2012-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -60,6 +60,7 @@ files:
60
60
  - lib/repomap.rb
61
61
  - lib/repomap/add.rb
62
62
  - lib/repomap/config.rb
63
+ - lib/repomap/find.rb
63
64
  - lib/repomap/helpers.rb
64
65
  - lib/repomap/list.rb
65
66
  - lib/repomap/remove.rb