mkgitignore 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/bin/mkgitignore +18 -0
- data/lib/mkgitignore/commands/build.rb +25 -0
- data/lib/mkgitignore/commands/list.rb +8 -0
- data/lib/mkgitignore/commands/listbuild.rb +18 -0
- data/lib/mkgitignore/commands/search.rb +14 -0
- data/lib/mkgitignore/version.rb +8 -0
- data/lib/mkgitignore.rb +147 -0
- data/mkgitignore.gemspec +23 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Keith Smiley
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Mkgitignore
|
2
|
+
|
3
|
+
Create gitignores from [Github's templates](https://github.com/github/gitignore/) from the command line.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
```
|
8
|
+
[sudo] gem install mkgitignore
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Run `mkgitignore` from the command line to see the different commands
|
14
|
+
|
15
|
+
EX: `mkgitignore build osx objective-c` combines the OSX and Objective-C templates into a the `.gitignore` in the current directory
|
16
|
+
|
17
|
+
### Contributing
|
18
|
+
|
19
|
+
1. Fork it
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/mkgitignore
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'commander/import'
|
4
|
+
require 'mkgitignore'
|
5
|
+
|
6
|
+
# Thanks @mattt
|
7
|
+
HighLine.track_eof = false # Fix for built-in Ruby
|
8
|
+
Signal.trap("INT") { exit } # Suppress backtrace when exiting command
|
9
|
+
|
10
|
+
program :version, Mkgitignore::VERSION
|
11
|
+
program :description, 'Create Gitignore files from the Github templates repo'
|
12
|
+
|
13
|
+
program :help, 'Author', Mkgitignore::AUTHOR
|
14
|
+
program :help, 'Website', Mkgitignore::EMAIL
|
15
|
+
program :help_formatter, :compact
|
16
|
+
|
17
|
+
default_command :help
|
18
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
command :build do |c|
|
2
|
+
c.syntax = 'mkgitignore build TEMPLATE_NAMES [options]'
|
3
|
+
c.summary = 'Create a new gitignore with the passed templates'
|
4
|
+
c.description = 'Combines passed Gitignore templates and creates a new gitignore with the result'
|
5
|
+
c.example 'Create a gitignore file with multiple passed templates', 'mkgitignore build osx objective-c'
|
6
|
+
c.option '--no-backup', 'Doesn\'t back up previous gitignore to backup.gitignore'
|
7
|
+
c.option '--dry-run', 'Prints out the would be contents of the gitignore'
|
8
|
+
c.action do |args, options|
|
9
|
+
if args.count < 1
|
10
|
+
puts "You must enter one or more template names. `mkgitignore build -h` for usage".red
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
templates = Mkgitignore::searchForTemplatesWithNames(args)
|
15
|
+
|
16
|
+
gitignore = String.new
|
17
|
+
templates.each { |t| gitignore += Mkgitignore::downloadFromURL(t["url"], t["name"]) }
|
18
|
+
|
19
|
+
if options.dry_run
|
20
|
+
puts gitignore
|
21
|
+
else
|
22
|
+
Mkgitignore::writeGitignore(gitignore, options.no_backup)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
command :list do |c|
|
2
|
+
c.syntax = 'mkgitignore list'
|
3
|
+
c.summary = 'List all the avaliable gitignore templates'
|
4
|
+
c.description = 'Prints every template within all subfolders of the Github Gitignore templates repository'
|
5
|
+
c.action do |args, options|
|
6
|
+
Mkgitignore::templatesFromURL(Mkgitignore::GITIGNORE_URL).each { |template| puts File.basename(template["name"], ".*") }
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
command :listbuild do |c|
|
2
|
+
c.syntax = 'mkgitignore listbuild'
|
3
|
+
c.summary = 'Create a gitignore by choosing from the master list'
|
4
|
+
c.description = 'Displays a list of every avaliable gitignore and asks for templates to add to the gitignore'
|
5
|
+
c.example 'Display the list and choose templates', 'mkgitignore listbuild'
|
6
|
+
c.option '--no-backup', 'Doesn\'t back up previous gitignore to backup.gitignore'
|
7
|
+
c.option '--dry-run', 'Prints out the would be contents of the gitignore'
|
8
|
+
c.action do |args, options|
|
9
|
+
gitignore = Mkgitignore::printAllTemplates
|
10
|
+
|
11
|
+
if options.dry_run
|
12
|
+
puts gitignore
|
13
|
+
else
|
14
|
+
Mkgitignore::writeGitignore(gitignore, options.no_backup)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
command :search do |c|
|
2
|
+
c.syntax = 'mkgitignore search TEMPLATE_NAMES'
|
3
|
+
c.summary = 'Search avaliable gitignore templates'
|
4
|
+
c.description = 'Searches all the templates in the Github gitignore templates repository'
|
5
|
+
c.example 'Search for a specific template', 'mkgitignore search objective-c'
|
6
|
+
c.action do |args, options|
|
7
|
+
templates = Mkgitignore::searchForTemplatesWithNames(args)
|
8
|
+
if templates.count > 0
|
9
|
+
templates.each { |t| puts File.basename(t["name"], ".*") }
|
10
|
+
else
|
11
|
+
puts "No matching templates found".red
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/mkgitignore.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'mkgitignore/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'colored'
|
4
|
+
require 'JSON'
|
5
|
+
|
6
|
+
module Mkgitignore
|
7
|
+
def self.templatesFromURL(url)
|
8
|
+
begin
|
9
|
+
response = RestClient.get(url)
|
10
|
+
rescue => e
|
11
|
+
begin
|
12
|
+
response = JSON.parse(e.response)
|
13
|
+
puts "Error: #{ response["message"] }".red
|
14
|
+
rescue JSON::ParserError => e
|
15
|
+
puts "Failed to connect to Github and to parse error. Error: #{ e.response }".red
|
16
|
+
end
|
17
|
+
exit
|
18
|
+
end
|
19
|
+
|
20
|
+
case response.code
|
21
|
+
when 200
|
22
|
+
file_array = Array.new
|
23
|
+
begin
|
24
|
+
json = JSON.parse(response.body)
|
25
|
+
rescue JSON::ParserError => e
|
26
|
+
puts "Failed to decode response #{ e.response }".red
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
|
30
|
+
json.each do |file|
|
31
|
+
name = file["name"].to_s
|
32
|
+
if name.include? ".gitignore"
|
33
|
+
file_array << file
|
34
|
+
else
|
35
|
+
if file["type"] == "dir"
|
36
|
+
file_array += templatesFromURL(file["url"])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
file_array.sort! { |x, y| x["name"] <=> y["name"] }
|
42
|
+
file_array
|
43
|
+
else
|
44
|
+
puts "Github returned an error #{ response }".red
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.searchForTemplatesWithNames(names)
|
49
|
+
result = Array.new
|
50
|
+
templates = Mkgitignore::templatesFromURL(Mkgitignore::GITIGNORE_URL)
|
51
|
+
templates.each do |t|
|
52
|
+
file_name = File.basename(t["name"], ".*")
|
53
|
+
names.each do |name|
|
54
|
+
if name.casecmp(file_name) == 0
|
55
|
+
result << t
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.downloadFromURL(url, name)
|
64
|
+
begin
|
65
|
+
response = RestClient.get(url, {:accept => "application/vnd.github.VERSION.raw"})
|
66
|
+
rescue => e
|
67
|
+
begin
|
68
|
+
response = JSON.parse(e.response)
|
69
|
+
puts "Error: #{ response["message"] }".red
|
70
|
+
rescue JSON::ParserError => e
|
71
|
+
puts "Failed to connect to Github and to parse error. Error: #{ e.response }".red
|
72
|
+
end
|
73
|
+
exit
|
74
|
+
end
|
75
|
+
|
76
|
+
"####### #{ File.basename(name, ".*") } #######\n#{ response.to_str.gsub(/\r/, "") }\n\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
def self.printAllTemplates
|
80
|
+
templates = Mkgitignore::templatesFromURL(Mkgitignore::GITIGNORE_URL)
|
81
|
+
templates.each_with_index do |template, index|
|
82
|
+
file_name = File.basename(template["name"], ".*")
|
83
|
+
puts "#{ index + 1}: #{ file_name }"
|
84
|
+
end
|
85
|
+
|
86
|
+
selectionArray = Array.new
|
87
|
+
|
88
|
+
begin
|
89
|
+
print("Enter a number to download (0 to stop): ")
|
90
|
+
selection = $stdin.gets.to_i - 1
|
91
|
+
if selectionArray.include? selection
|
92
|
+
puts "#{ selection + 1 } was already entered.".red
|
93
|
+
else
|
94
|
+
if selection > 0 && selection < templates.count
|
95
|
+
selectionArray << selection
|
96
|
+
else
|
97
|
+
if selection > 0
|
98
|
+
puts "#{ selection + 1 } is invalid".red
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end while selection > 0
|
103
|
+
|
104
|
+
if selectionArray.count < 1
|
105
|
+
puts "No gitignores selected".red
|
106
|
+
exit
|
107
|
+
end
|
108
|
+
|
109
|
+
gitignore = String.new
|
110
|
+
# selectionArray.each { |t| gitignore += Mkgitignore::downloadFromURL(t["url"], t["name"]) }
|
111
|
+
selectionArray.each { |x| gitignore += Mkgitignore::downloadFromURL(templates[x]["url"], templates[x]["name"]) }
|
112
|
+
|
113
|
+
gitignore
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.writeGitignore(gitignore, nobackup)
|
117
|
+
if !nobackup && File.exists?(Mkgitignore::GITIGNORE_FILE_NAME)
|
118
|
+
FileUtils.mv Mkgitignore::GITIGNORE_FILE_NAME, Mkgitignore::BACKUP_FILE_NAME, :force => true
|
119
|
+
if File.exists?(Mkgitignore::GITIGNORE_FILE_NAME)
|
120
|
+
puts "Failed to backup #{ Mkgitignore::GITIGNORE_FILE_NAME }".red
|
121
|
+
else
|
122
|
+
puts "Backed up to #{ Mkgitignore::BACKUP_FILE_NAME }".green
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
if File.exists?(Mkgitignore::GITIGNORE_FILE_NAME)
|
127
|
+
FileUtils.rm(Mkgitignore::GITIGNORE_FILE_NAME, :force => true)
|
128
|
+
if File.exists?(Mkgitignore::GITIGNORE_FILE_NAME)
|
129
|
+
puts "Failed to remove old #{ Mkgitignore::GITIGNORE_FILE_NAME }".red
|
130
|
+
else
|
131
|
+
puts "Removed old #{ Mkgitignore::GITIGNORE_FILE_NAME }".green
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
file = File.open(Mkgitignore::GITIGNORE_FILE_NAME, "w")
|
136
|
+
file << gitignore
|
137
|
+
file.close()
|
138
|
+
puts "Finished writing #{ Mkgitignore::GITIGNORE_FILE_NAME }".green
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
require 'mkgitignore/commands/list'
|
144
|
+
require 'mkgitignore/commands/search'
|
145
|
+
require 'mkgitignore/commands/build'
|
146
|
+
require 'mkgitignore/commands/listbuild'
|
147
|
+
|
data/mkgitignore.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mkgitignore/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "mkgitignore"
|
8
|
+
gem.version = Mkgitignore::VERSION
|
9
|
+
gem.authors = Mkgitignore::AUTHOR
|
10
|
+
gem.email = Mkgitignore::EMAIL
|
11
|
+
gem.description = "Easily creates gitignores from the Github gitignore templates repository"
|
12
|
+
gem.summary = "Create gitignores from Github's templates"
|
13
|
+
gem.homepage = "https://github.com/Keithbsmiley/mkgitignore"
|
14
|
+
|
15
|
+
gem.add_runtime_dependency "commander", "~> 4.1.3"
|
16
|
+
gem.add_runtime_dependency "rest-client", "~> 1.6.7"
|
17
|
+
gem.add_runtime_dependency "colored", "~> 1.2"
|
18
|
+
|
19
|
+
gem.files = `git ls-files`.split($/)
|
20
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
21
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
+
gem.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mkgitignore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Keith Smiley
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-17 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: commander
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 4.1.3
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 4.1.3
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rest-client
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.6.7
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.6.7
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: colored
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.2'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
description: Easily creates gitignores from the Github gitignore templates repository
|
63
|
+
email: keithbsmiley@gmail.com
|
64
|
+
executables:
|
65
|
+
- mkgitignore
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- LICENSE.txt
|
72
|
+
- README.md
|
73
|
+
- Rakefile
|
74
|
+
- bin/mkgitignore
|
75
|
+
- lib/mkgitignore.rb
|
76
|
+
- lib/mkgitignore/commands/build.rb
|
77
|
+
- lib/mkgitignore/commands/list.rb
|
78
|
+
- lib/mkgitignore/commands/listbuild.rb
|
79
|
+
- lib/mkgitignore/commands/search.rb
|
80
|
+
- lib/mkgitignore/version.rb
|
81
|
+
- mkgitignore.gemspec
|
82
|
+
homepage: https://github.com/Keithbsmiley/mkgitignore
|
83
|
+
licenses: []
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.24
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Create gitignores from Github's templates
|
106
|
+
test_files: []
|