peacock 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -0
- data/README.md +23 -19
- data/Rakefile +7 -0
- data/exe/peacock +4 -1
- data/lib/peacock/ignorer.rb +67 -0
- data/lib/peacock/parse_hash.rb +24 -0
- data/lib/peacock/parser.rb +65 -0
- data/lib/peacock/peacock_exception.rb +7 -0
- data/lib/peacock/startup_manager.rb +32 -0
- data/lib/peacock/version.rb +1 -1
- data/lib/peacock.rb +17 -2
- data/peacock.gemspec +1 -0
- metadata +21 -4
- data/bin/console +0 -14
- data/bin/setup +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fac84611573a5fd44f62cde9faa8a1629218d3f8
|
4
|
+
data.tar.gz: 90c4812009455f94839f36e632eb2c7166395571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08ef5075610bae74a67ac04cfb9457f6bfbc2908e10ea56a50866b277fbc9017d325e7ae58eabcf60157755f0ba77f7ef721c16bc8180f386710a2db426df16
|
7
|
+
data.tar.gz: 45b12fe8af6c20d2636e30acf764b5276b296e241dbff7867b670234d834577613f44f5f3b12fdf39d65c46146faebbd951e4cded887357046bd531396a3a206
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,35 +1,39 @@
|
|
1
1
|
# Peacock
|
2
2
|
|
3
|
-
Peacock is
|
4
|
-
This gem will make it easy to add files to .gitignore
|
3
|
+
Peacock is a small tool to easily manage your .gitignore written in ruby.
|
5
4
|
|
6
|
-
|
5
|
+
At the moment, Peacock can only be executed from the root directory of your repository.
|
6
|
+
|
7
|
+
In order to perform your changes on .gitignore, peacock will automatically add all current files to the index
|
8
|
+
and perform a commit before and after you execute peacock.
|
7
9
|
|
8
10
|
## Installation
|
9
11
|
|
10
12
|
Add this line to your application's Gemfile:
|
11
13
|
|
12
|
-
|
13
|
-
gem 'peacock'
|
14
|
-
```
|
15
|
-
|
16
|
-
And then execute:
|
17
|
-
|
18
|
-
$ bundle
|
19
|
-
|
20
|
-
Or install it yourself as:
|
14
|
+
Install by executing:
|
21
15
|
|
22
16
|
$ gem install peacock
|
23
17
|
|
24
18
|
## Usage
|
25
19
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
20
|
+
Usage:
|
21
|
+
peacock [options] [files/directories]
|
22
|
+
|
23
|
+
Options:
|
24
|
+
-h, [--help] # show this text
|
25
|
+
-r, [--root] # use root .gitignore (not functional yet)
|
26
|
+
-e, [--extract] # extract file from .gitignore (not functional yet)
|
27
|
+
-l, [--list] # list all ignored directories and files (not functional yet)
|
28
|
+
|
29
|
+
## TODO
|
30
|
+
|
31
|
+
- ruby-git does not recognize a repo unless you are in the root directory. a different mechanism is needed
|
32
|
+
- implement own small git library for peacock
|
33
|
+
- create a test environment and better tests
|
34
|
+
- add functionalities
|
35
|
+
- custom commit messages
|
36
|
+
- comments in .gitignore
|
33
37
|
|
34
38
|
## Contributing
|
35
39
|
|
data/Rakefile
CHANGED
data/exe/peacock
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class Ignorer
|
4
|
+
|
5
|
+
def self.ignore(opt_hash)
|
6
|
+
ignorer = Ignorer.new(opt_hash)
|
7
|
+
ignorer.commit_all('peacock: before .gitignore commit')
|
8
|
+
ignorer.ignore_files_and_directories
|
9
|
+
ignorer.clear_cache
|
10
|
+
ignorer.commit_all('peacock: after .gitignore commit')
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(opt_hash)
|
14
|
+
@hash = opt_hash
|
15
|
+
@git_ignore = File.open('.gitignore', 'a+')
|
16
|
+
@repo = Git.open Dir.pwd
|
17
|
+
end
|
18
|
+
|
19
|
+
def clear_cache
|
20
|
+
# totally ugly, but ruby-git does not support git rm -r --cached
|
21
|
+
Open3.popen3('git rm -r --cached .') do |stdin, stdout, stderr, thread|
|
22
|
+
# ignore output
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def commit_all(message)
|
27
|
+
begin
|
28
|
+
@repo.add(all: true)
|
29
|
+
@repo.commit_all(message)
|
30
|
+
rescue
|
31
|
+
# do nothing
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def ignore_files_and_directories
|
36
|
+
ignore_files
|
37
|
+
ignore_directories
|
38
|
+
end
|
39
|
+
|
40
|
+
def ignore_directories
|
41
|
+
@hash[:dirs].each do |dir|
|
42
|
+
dir = dir + '/' unless dir =~ /\/$/ # add backlash to dir name if it does not exist yet
|
43
|
+
check_and_write(dir)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def ignore_files
|
48
|
+
@hash[:files].each do |file|
|
49
|
+
check_and_write(file)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def check_and_write(str)
|
54
|
+
@git_ignore.write(str + "\n") unless entry_exists?(str)
|
55
|
+
@git_ignore.rewind
|
56
|
+
end
|
57
|
+
|
58
|
+
def entry_exists?(entry)
|
59
|
+
@git_ignore.each do |line|
|
60
|
+
return true if line.chomp == entry
|
61
|
+
end
|
62
|
+
false
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class ParseHash
|
4
|
+
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@hash = Hash.new
|
9
|
+
@hash[:opts] = Array.new
|
10
|
+
@hash[:files] = Array.new
|
11
|
+
@hash[:dirs] = Array.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def push(type, str)
|
15
|
+
@hash[type].push(str)
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
hash.to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class Parser
|
4
|
+
|
5
|
+
def self.parse
|
6
|
+
parser = Parser.new
|
7
|
+
parser.check_if_help_text
|
8
|
+
parser.parse_args.hash
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_args
|
12
|
+
return_hash = Peacock::ParseHash.new
|
13
|
+
|
14
|
+
ARGV.each do |arg|
|
15
|
+
type = determine_type arg
|
16
|
+
return_hash.push(type, arg) unless type.nil?
|
17
|
+
end
|
18
|
+
|
19
|
+
return_hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def determine_type(opt)
|
23
|
+
if File.directory?(opt)
|
24
|
+
:dirs
|
25
|
+
elsif File.file?(opt)
|
26
|
+
:files
|
27
|
+
elsif options.include?(opt)
|
28
|
+
:opts
|
29
|
+
else
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def check_if_help_text
|
35
|
+
if should_print_help?
|
36
|
+
puts help_text
|
37
|
+
exit 0
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def should_print_help?
|
42
|
+
ARGV.size == 0 || ARGV[0] == '-h' || ARGV[0] == '--help'
|
43
|
+
end
|
44
|
+
|
45
|
+
def help_text
|
46
|
+
<<-EOF.gsub /^ */, ''
|
47
|
+
Usage:
|
48
|
+
\tpeacock [options] [files/directories]
|
49
|
+
|
50
|
+
Options:
|
51
|
+
\t-h, [--help] # show this text
|
52
|
+
\t-r, [--root] # use root .gitignore (not functional yet)
|
53
|
+
\t-e, [--extract] # extract file from .gitignore (not functional yet)
|
54
|
+
\t-l, [--list] # list all ignored directories and files (not functional yet)
|
55
|
+
EOF
|
56
|
+
end
|
57
|
+
|
58
|
+
def options
|
59
|
+
['-r', '--root', '-e', '--extract', '-l', '--list']
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class StartupManager
|
4
|
+
|
5
|
+
def self.check_peacock_requirements
|
6
|
+
startup = StartupManager.new
|
7
|
+
|
8
|
+
begin
|
9
|
+
startup.check_git_repository
|
10
|
+
rescue PeacockError
|
11
|
+
puts 'An error occured. Make sure you are in a git repository and git is installed.'
|
12
|
+
exit 1
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def check_git_repository
|
17
|
+
raise PeacockError unless git_repository?
|
18
|
+
end
|
19
|
+
|
20
|
+
# checks if current directory is a git repository
|
21
|
+
def git_repository?
|
22
|
+
begin
|
23
|
+
Git.open Dir.pwd
|
24
|
+
true
|
25
|
+
rescue
|
26
|
+
false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
data/lib/peacock/version.rb
CHANGED
data/lib/peacock.rb
CHANGED
@@ -1,5 +1,20 @@
|
|
1
|
-
require
|
1
|
+
require 'git'
|
2
|
+
require 'open3'
|
3
|
+
|
4
|
+
require 'peacock/version'
|
5
|
+
require 'peacock/peacock_exception'
|
6
|
+
require 'peacock/startup_manager'
|
7
|
+
require 'peacock/parse_hash'
|
8
|
+
require 'peacock/parser'
|
9
|
+
require 'peacock/ignorer'
|
10
|
+
|
2
11
|
|
3
12
|
module Peacock
|
4
|
-
|
13
|
+
|
14
|
+
def self.execute
|
15
|
+
Peacock::StartupManager.check_peacock_requirements
|
16
|
+
parse_hash = Peacock::Parser.parse
|
17
|
+
Peacock::Ignorer.ignore(parse_hash)
|
18
|
+
end
|
19
|
+
|
5
20
|
end
|
data/peacock.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peacock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Paling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: git
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
description: Longer Description
|
42
56
|
email:
|
43
57
|
- christian.paling@googlemail.com
|
@@ -52,10 +66,13 @@ files:
|
|
52
66
|
- LICENSE.txt
|
53
67
|
- README.md
|
54
68
|
- Rakefile
|
55
|
-
- bin/console
|
56
|
-
- bin/setup
|
57
69
|
- exe/peacock
|
58
70
|
- lib/peacock.rb
|
71
|
+
- lib/peacock/ignorer.rb
|
72
|
+
- lib/peacock/parse_hash.rb
|
73
|
+
- lib/peacock/parser.rb
|
74
|
+
- lib/peacock/peacock_exception.rb
|
75
|
+
- lib/peacock/startup_manager.rb
|
59
76
|
- lib/peacock/version.rb
|
60
77
|
- peacock.gemspec
|
61
78
|
homepage: https://github.com/bakku/peacock
|
data/bin/console
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "peacock"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|