ignore-it 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe4f3fcd1823b63622f37773342d0f190a6b1da199eace1cd08c15feec633295
4
- data.tar.gz: eca95760a611df332ca4da415e78311d148ca76804c6ab7281a7f335f682d0b9
3
+ metadata.gz: 80d9566a34fc947b8be73b0c0c807829ee5a610cf4f07b9c078ef88532f4256d
4
+ data.tar.gz: 731a3c6d125d0b3a3e8654410788dd8b257ab9812397c3d4f7dc8cb4aea6dc1e
5
5
  SHA512:
6
- metadata.gz: 403f70e0f8030520a8ce81d1faefaf46fcf3aebf2c49e2e5ad3cec1050dd588f2f00fe1b82f739fc4489c2c14117cceb44d7cd135c94a586c48755a1477d5f70
7
- data.tar.gz: 15616d052cacb118738549b0a58a4a68d09ae9b64be2e709010295d7c19c685812086032050abfb2b8611e45261a02ebed7a048e4cc893329a71039b6abe139b
6
+ metadata.gz: 35a98c0914b2b4213b45353fdfa11b396b383cd78fd467a228f5073d8ae792c538a72130c5c60ddce176648a1e6237d7bf50596f31ca549ce0615cc099115042
7
+ data.tar.gz: 93e85ef86fab76aa03bf1337151261829815c313a373497fa28c6b5a262580278dc14a02ddd941c51e671c463066f228b634706dae71d45d1779add536ec86cd
@@ -3,5 +3,7 @@
3
3
  require 'optparse'
4
4
  require "ignore_it"
5
5
 
6
- tool = IgnoreIt::Main.new
7
- tool.start
6
+ # tool = IgnoreIt::Main.new
7
+ # tool.start
8
+ tool = IgnoreIt::CLI
9
+ tool.start(ARGV)
@@ -0,0 +1,8 @@
1
+ ########################
2
+ # CONFIG for ignore-it #
3
+ ########################
4
+
5
+ # Set ABSOLUTE path to the directory where own gitignore files are stored
6
+ # Default path is ~/.ignore-it/gitignores
7
+ # OPTIONS: "default", "absolute_path"
8
+ own_gitignore_path: "default"
@@ -1,42 +1,80 @@
1
+ # frozen_string_literal: true
1
2
  require 'net/http'
2
3
  require 'json'
3
4
  require 'colorize'
4
5
  require 'readline'
5
6
  require 'ignore_it/list'
7
+ require 'ignore_it/config'
6
8
  require 'ignore_it/creator'
9
+ require 'thor'
7
10
 
8
11
  module IgnoreIt
9
- class Main
10
- # constructor
11
- def initialize
12
- @url = "https://www.toptal.com/developers/gitignore/api/list?format=json"
13
- @options = {}
14
- @list = List.new
12
+ class CLI < Thor
13
+ def initialize(*args)
14
+ super
15
+ @config = Config.new
15
16
  @creator = Creator.new
17
+ @list = List.new
18
+ $glob_settings[:output] = "./.gitignore"
16
19
  end
17
20
 
18
- def start
21
+ class_options force: :boolean, output: :string
19
22
 
20
- ARGV << '-h' if ARGV.empty?
23
+ desc "add [templateName]", "Select gitignore template to create a .gitignore file
24
+ or add a template to an existing .gitignore file"
25
+ def add(*templateName)
26
+ if options[:output]
27
+ return false unless @creator.check_output_path(options[:output])
28
+ $glob_settings[:output] = if options[:output][-1] == '/'
29
+ options[:output] + '.gitignore'
30
+ else
31
+ options[:output] + '/.gitignore'
32
+ end
33
+ end
34
+ if options[:force]
35
+ $glob_settings[:force] = true
36
+ end
37
+ templateName.each do |name|
38
+ name = name.downcase
39
+ if @list.check_list(name)
40
+ @creator.create_api_ignore(name)
41
+ else
42
+ puts "The template #{name} you tried to fetch does not exist".colorize(:red)
43
+ puts "Please checkout the available templates with " + "ignore-it list".colorize(:green)
44
+ end
45
+ end
46
+ end
21
47
 
22
- OptionParser.new do |parser|
23
- parser.banner = "How to Use ignore-it: Pass one of the following options: e.g => ignore-it -f csharp"
24
- parser.on(
25
- "-f ", "--file FILE", "Select gitignore template to fetch"
26
- ) do |file|
27
- file = file.downcase
28
- if @list.check_list(file)
29
- @creator.create_ignore(file)
30
- else
31
- puts "The template you tried to fetch does not exist".colorize(:red)
32
- puts "Please checkout the available templates with " + "ignore-it -l".colorize(:green)
33
- end
34
- # @options[:file] = true
48
+ desc "own [fileName]", "Select user-created template from the folder specified in ~/.ignore-it/config.yml. Default is ~/.ignore-it/gitignores/."
49
+ def own(*fileName)
50
+ if options[:output]
51
+ return false unless @creator.check_output_path(options[:output])
52
+ $glob_settings[:output] = if options[:output][-1] == '/'
53
+ options[:output] + '.gitignore'
54
+ else
55
+ options[:output] + '/.gitignore'
35
56
  end
36
- parser.on("-l", "--list", "Show List of available .gitignore entries") do
37
- @list.show_list
57
+ end
58
+ if options[:force] == true
59
+ $glob_settings[:force] = true
60
+ end
61
+ fileName.each do |name|
62
+ if @list.check_own_files(name)
63
+ @creator.create_own_ignore(name)
64
+ else
65
+ puts "The template #{name} you tried to create does not exist".colorize(:red)
66
+ puts "The following templates are available:".colorize(:red)
67
+ @list.show_own_files
38
68
  end
39
- end.parse!
69
+ end
70
+ end
71
+
72
+ desc "list", "Show List of available .gitignore entries"
73
+ def list
74
+ puts "---- Available templates from gitignore.io: ----"
75
+ @list.show_list
76
+ puts "---- Available user templates (see ~/.ignore-it/config.yml) ----"
77
+ @list.show_own_files
40
78
  end
41
79
  end
42
80
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+
4
+ module IgnoreIt
5
+ class Config
6
+ attr_accessor :config
7
+
8
+ def initialize
9
+ $glob_settings = {}
10
+ create_initial_config
11
+ load_config
12
+ end
13
+
14
+ def print_config
15
+ puts $glob_settings.to_yaml
16
+ end
17
+
18
+ # Load user config from config directory
19
+ def load_config
20
+ Dir.chdir(Dir.home) do
21
+ if File.exist?(".ignore-it/config.yml")
22
+ $glob_settings = YAML.load_file(".ignore-it/config.yml")
23
+ else
24
+ puts "Failed to load user config in ~/.ignore-it/config.yml".colorize(:red)
25
+ puts "Defaulting...".colorize(:red)
26
+ $glob_settings = YAML.load_file(find_gem_root + "/default_config.yml")
27
+ end
28
+ end
29
+ end
30
+
31
+ # Find the gems install directory
32
+ def find_gem_root
33
+ spec = Gem::Specification.find_by_name("ignore-it")
34
+ spec.gem_dir
35
+ end
36
+
37
+ # Create initial user config and folders in home directory
38
+ def create_initial_config
39
+ Dir.chdir(Dir.home) do
40
+ unless Dir.exist?(".ignore-it")
41
+ Dir.mkdir(".ignore-it")
42
+ Dir.mkdir(".ignore-it/gitignores")
43
+ defaultConfig = File.read(find_gem_root + "/default_config.yml")
44
+ File.write(".ignore-it/config.yml", defaultConfig)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # lib/creation.rb
2
3
  require 'ignore_it/list'
3
4
  require 'readline'
@@ -6,55 +7,85 @@ require 'colorize'
6
7
  module IgnoreIt
7
8
  class Creator
8
9
  def initialize
9
- list = List.new
10
- @jsonResponse = list.jsonResponse
10
+ @list = List.new
11
+ @jsonResponse = @list.jsonResponse
11
12
  end
12
13
 
13
- # Code here
14
- def create_ignore(name)
15
- template = @jsonResponse[name]
16
- contents = template["contents"]
17
-
14
+ def create_file(contents, name)
18
15
  puts "Creating .gitignore for " + name.colorize(:green)
19
-
20
- if File.exist?(".gitignore")
21
- # Store the state of the terminal
22
- sttySave = %x(stty -g).chomp
23
- overwrite = false
24
-
25
- begin
26
- puts "File already exists! Overwrite? [y/n]?"
27
- while (line = Readline.readline('> ', true).downcase)
28
- # if (line.empty? or line != "y" or line != "n")
29
-
30
- if line == "y"
31
- overwrite = true
32
- break
33
- # puts "yo"
34
- elsif line == "n"
35
- break
36
- # puts "ney"
37
- elsif (line != "y") || (line != "n")
38
- puts "Please provide a correct format (y or n)".colorize(:red)
39
- # puts "wut"
16
+ unless $glob_settings[:force]
17
+ if File.exist?($glob_settings[:output])
18
+ sttySave = %x(stty -g).chomp # Store the state of the terminal
19
+ overwrite = false
20
+ append = false
21
+ begin
22
+ puts "File" + " .gitignore ".colorize(:yellow) + "already exists!"
23
+ puts "Overwrite or append? [y => yes | a => append | n => no]?"
24
+ while (line = Readline.readline('> ', true).downcase)
25
+ if line == "y"
26
+ overwrite = true
27
+ break
28
+ elsif line == "n"
29
+ break
30
+ elsif line == "a"
31
+ append = true
32
+ break
33
+ elsif (line != "y") || (line != "n") || (line != "a")
34
+ puts "Please provide a correct format (y or n)".colorize(:red)
35
+ end
40
36
  end
37
+ rescue Interrupt
38
+ system('stty', sttySave) # Restore
39
+ exit
41
40
  end
42
- rescue Interrupt => e
43
- system('stty', sttySave) # Restore
44
- exit
45
- end
46
41
 
47
- if overwrite
48
- File.write("./.gitignore", contents)
49
- puts ".gitignore has been created!".colorize(:green)
42
+ if overwrite
43
+ File.write($glob_settings[:output], contents)
44
+ puts ".gitignore has been created!".colorize(:green)
45
+ elsif append
46
+ gitignoreContents = File.read($glob_settings[:output])
47
+ puts "Adding .gitignore content from " + name.colorize(:green) + " to existing .gitignore File"
48
+ gitignoreContents += contents
49
+ File.write($glob_settings[:output], gitignoreContents)
50
+ else
51
+ puts ".gitignore has NOT been created! Terminating process!".colorize(:red)
52
+ end
50
53
  else
51
- puts ".gitignore has NOT been created! Terminating process!".colorize(:red)
54
+ File.write($glob_settings[:output], contents)
55
+ puts ".gitignore has been created!".colorize(:green)
52
56
  end
53
-
54
57
  else
55
- File.write("./.gitignore", contents)
58
+ File.write($glob_settings[:output], contents)
56
59
  puts ".gitignore has been created!".colorize(:green)
57
60
  end
58
61
  end
62
+
63
+ def create_own_ignore(name)
64
+ contents = ""
65
+ if $glob_settings["own_gitignore_path"] == "default"
66
+ Dir.chdir(Dir.home) do
67
+ contents = File.read(".ignore-it/gitignores/" + name)
68
+ end
69
+ else
70
+ Dir.chdir($glob_settings["own_gitignore_path"]) do
71
+ contents = File.read(name)
72
+ end
73
+ end
74
+ create_file(contents, name)
75
+ end
76
+
77
+ def create_api_ignore(name)
78
+ template = @jsonResponse[name]
79
+ contents = template["contents"]
80
+ create_file(contents, name)
81
+ end
82
+
83
+ def check_output_path(name)
84
+ if Dir.exist?(name)
85
+ true
86
+ else
87
+ puts "The Output Path you provided does currently not exist, please create it manually before using --output".colorize(:red)
88
+ end
89
+ end
59
90
  end
60
91
  end
@@ -10,10 +10,44 @@ module IgnoreIt
10
10
  @url = "https://www.toptal.com/developers/gitignore/api/list?format=json"
11
11
  @response = Net::HTTP.get(URI(@url))
12
12
  @jsonResponse = JSON.parse(@response)
13
+ load_own_files
13
14
  end
14
15
 
15
- attr_reader :jsonResponse
16
+ attr_reader :jsonResponse, :ownFiles
16
17
 
18
+ # Load own gitignore templates from the directory specified in the config file
19
+ def load_own_files
20
+ @ownFiles = if $glob_settings["own_gitignore_path"] == "default"
21
+ Dir.chdir(Dir.home) do
22
+ Dir.entries(".ignore-it/gitignores/").select do |files|
23
+ files unless files =~ /^..?$/ # some regex magic to remove "." and ".."
24
+ end
25
+ end
26
+ else
27
+ Dir.chdir($glob_settings["own_gitignore_path"]) do
28
+ Dir.entries(".").select do |files|
29
+ files unless files =~ /^..?$/
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ # Check if the requested template exists
36
+ def check_own_files(file)
37
+ if @ownFiles.include?(file)
38
+ exists = true
39
+ end
40
+ exists
41
+ end
42
+
43
+ # Print all own gitignore templates
44
+ def show_own_files
45
+ @ownFiles.each do |file|
46
+ puts file
47
+ end
48
+ end
49
+
50
+ # Check the API List
17
51
  def check_list(file)
18
52
  exists = false
19
53
 
@@ -27,9 +61,9 @@ module IgnoreIt
27
61
  exists
28
62
  end
29
63
 
64
+ # Print all gitignore templates fetched by the API
30
65
  def show_list
31
66
  sortedArray = @jsonResponse.sort
32
-
33
67
  sortedArray.each do |entry|
34
68
  puts entry.first
35
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ignore-it
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Macho
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-11-07 00:00:00.000000000 Z
12
+ date: 2020-11-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -17,28 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 11.3.0
20
+ version: 11.2.2
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 11.3.0
27
+ version: 11.2.2
28
28
  - !ruby/object:Gem::Dependency
29
- name: rubocop
29
+ name: minitest
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - "~>"
32
+ - - ">="
33
33
  - !ruby/object:Gem::Version
34
- version: '1.2'
34
+ version: '0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - "~>"
39
+ - - ">="
40
40
  - !ruby/object:Gem::Version
41
- version: '1.2'
41
+ version: '0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: colorize
44
44
  requirement: !ruby/object:Gem::Requirement
@@ -53,15 +53,35 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: 0.8.1
56
- description:
56
+ - !ruby/object:Gem::Dependency
57
+ name: thor
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 1.0.1
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.1
70
+ description: |2
71
+ Feel it's sometimes cumbersome to browse to a website, only to download a .gitignore?
72
+ We've got your back!
73
+ ignore-it is a small cli tool, which helps in fetching and creating .gitignore files from gitignore.io or local custom templates.
74
+ We try to keep runtime dependencies as small as possible and are using mostly standard ruby libraries.
57
75
  email:
58
76
  executables:
59
77
  - ignore-it
60
78
  extensions: []
61
79
  extra_rdoc_files: []
62
80
  files:
81
+ - "./default_config.yml"
63
82
  - bin/ignore-it
64
83
  - lib/ignore_it.rb
84
+ - lib/ignore_it/config.rb
65
85
  - lib/ignore_it/creator.rb
66
86
  - lib/ignore_it/list.rb
67
87
  homepage:
@@ -87,5 +107,5 @@ requirements: []
87
107
  rubygems_version: 3.0.3
88
108
  signing_key:
89
109
  specification_version: 4
90
- summary: ignore-it your command line tool for fetching .gitignore files
110
+ summary: ignore-it your command line tool for creating .gitignore files
91
111
  test_files: []