-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #51 from lolcatbois/release
Release
- Loading branch information
Showing
13 changed files
with
327 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'rake/testtask' | ||
|
||
task(default: "test") | ||
|
||
Rake::TestTask.new do |task| | ||
task.pattern = "test/*_test.rb" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
######################## | ||
# CONFIG for ignore-it # | ||
######################## | ||
|
||
# Set ABSOLUTE path to the directory where own gitignore files are stored | ||
# Default path is ~/.ignore-it/gitignores | ||
# OPTIONS: "default", "absolute_path" | ||
own_gitignore_path: "default" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
Gem::Specification.new do |s| | ||
s.name = 'ignore-it' | ||
s.version = "1.0.2" | ||
s.date = '2020-11-07' | ||
s.summary = 'ignore-it your command line tool for fetching .gitignore files' | ||
s.version = "1.1.0" | ||
s.date = '2020-11-13' | ||
s.summary = 'ignore-it your command line tool for creating .gitignore files' | ||
s.description = <<-EOF | ||
Feel it's sometimes cumbersome to browse to a website, only to download a .gitignore? | ||
We've got your back! | ||
ignore-it is a small cli tool, which helps in fetching and creating .gitignore files from gitignore.io or local custom templates. | ||
We try to keep runtime dependencies as small as possible and are using mostly standard ruby libraries. | ||
EOF | ||
s.authors = ["Felix Macho", "Simon Sölder"] | ||
s.metadata = { "source_code_uri" => "https://github.com/lolcatbois/ignore-it" } | ||
s.files = Dir.glob("{bin,lib}/**/*") | ||
s.files += ["./default_config.yml"] | ||
s.licenses = ['MIT'] | ||
s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
s.test_files = s.files.grep(%r{^test/}) | ||
s.require_paths = ["lib"] | ||
|
||
# DEPENDENCIES | ||
s.add_development_dependency("rake", "~> 11.3.0") | ||
s.add_development_dependency("rubocop", "~> 1.2") | ||
s.add_runtime_dependency('colorize', "~> 0.8.1") | ||
# DEV DEPENDENCIES | ||
s.add_development_dependency("rake", "~>11.2.2") | ||
s.add_development_dependency("minitest") | ||
|
||
# RUNTIME DEPENDENCIES | ||
s.add_runtime_dependency('colorize', "~>0.8.1") | ||
s.add_runtime_dependency('thor', "~>1.0.1") | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,80 @@ | ||
# frozen_string_literal: true | ||
require 'net/http' | ||
require 'json' | ||
require 'colorize' | ||
require 'readline' | ||
require 'ignore_it/list' | ||
require 'ignore_it/config' | ||
require 'ignore_it/creator' | ||
require 'thor' | ||
|
||
module IgnoreIt | ||
class Main | ||
# constructor | ||
def initialize | ||
@url = "https://www.toptal.com/developers/gitignore/api/list?format=json" | ||
@options = {} | ||
@list = List.new | ||
class CLI < Thor | ||
def initialize(*args) | ||
super | ||
@config = Config.new | ||
@creator = Creator.new | ||
@list = List.new | ||
$glob_settings[:output] = "./.gitignore" | ||
end | ||
|
||
def start | ||
class_options force: :boolean, output: :string | ||
|
||
ARGV << '-h' if ARGV.empty? | ||
desc "add [templateName]", "Select gitignore template to create a .gitignore file | ||
or add a template to an existing .gitignore file" | ||
def add(*templateName) | ||
if options[:output] | ||
return false unless @creator.check_output_path(options[:output]) | ||
$glob_settings[:output] = if options[:output][-1] == '/' | ||
options[:output] + '.gitignore' | ||
else | ||
options[:output] + '/.gitignore' | ||
end | ||
end | ||
if options[:force] | ||
$glob_settings[:force] = true | ||
end | ||
templateName.each do |name| | ||
name = name.downcase | ||
if @list.check_list(name) | ||
@creator.create_api_ignore(name) | ||
else | ||
puts "The template #{name} you tried to fetch does not exist".colorize(:red) | ||
puts "Please checkout the available templates with " + "ignore-it list".colorize(:green) | ||
end | ||
end | ||
end | ||
|
||
OptionParser.new do |parser| | ||
parser.banner = "How to Use ignore-it: Pass one of the following options: e.g => ignore-it -f csharp" | ||
parser.on( | ||
"-f ", "--file FILE", "Select gitignore template to fetch" | ||
) do |file| | ||
file = file.downcase | ||
if @list.check_list(file) | ||
@creator.create_ignore(file) | ||
else | ||
puts "The template you tried to fetch does not exist".colorize(:red) | ||
puts "Please checkout the available templates with " + "ignore-it -l".colorize(:green) | ||
end | ||
# @options[:file] = true | ||
desc "own [fileName]", "Select user-created template from the folder specified in ~/.ignore-it/config.yml. Default is ~/.ignore-it/gitignores/." | ||
def own(*fileName) | ||
if options[:output] | ||
return false unless @creator.check_output_path(options[:output]) | ||
$glob_settings[:output] = if options[:output][-1] == '/' | ||
options[:output] + '.gitignore' | ||
else | ||
options[:output] + '/.gitignore' | ||
end | ||
parser.on("-l", "--list", "Show List of available .gitignore entries") do | ||
@list.show_list | ||
end | ||
if options[:force] == true | ||
$glob_settings[:force] = true | ||
end | ||
fileName.each do |name| | ||
if @list.check_own_files(name) | ||
@creator.create_own_ignore(name) | ||
else | ||
puts "The template #{name} you tried to create does not exist".colorize(:red) | ||
puts "The following templates are available:".colorize(:red) | ||
@list.show_own_files | ||
end | ||
end.parse! | ||
end | ||
end | ||
|
||
desc "list", "Show List of available .gitignore entries" | ||
def list | ||
puts "---- Available templates from gitignore.io: ----" | ||
@list.show_list | ||
puts "---- Available user templates (see ~/.ignore-it/config.yml) ----" | ||
@list.show_own_files | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# frozen_string_literal: true | ||
require 'yaml' | ||
|
||
module IgnoreIt | ||
class Config | ||
attr_accessor :config | ||
|
||
def initialize | ||
$glob_settings = {} | ||
create_initial_config | ||
load_config | ||
end | ||
|
||
def print_config | ||
puts $glob_settings.to_yaml | ||
end | ||
|
||
# Load user config from config directory | ||
def load_config | ||
Dir.chdir(Dir.home) do | ||
if File.exist?(".ignore-it/config.yml") | ||
$glob_settings = YAML.load_file(".ignore-it/config.yml") | ||
else | ||
puts "Failed to load user config in ~/.ignore-it/config.yml".colorize(:red) | ||
puts "Defaulting...".colorize(:red) | ||
$glob_settings = YAML.load_file(find_gem_root + "/default_config.yml") | ||
end | ||
end | ||
end | ||
|
||
# Find the gems install directory | ||
def find_gem_root | ||
spec = Gem::Specification.find_by_name("ignore-it") | ||
spec.gem_dir | ||
end | ||
|
||
# Create initial user config and folders in home directory | ||
def create_initial_config | ||
Dir.chdir(Dir.home) do | ||
unless Dir.exist?(".ignore-it") | ||
Dir.mkdir(".ignore-it") | ||
Dir.mkdir(".ignore-it/gitignores") | ||
defaultConfig = File.read(find_gem_root + "/default_config.yml") | ||
File.write(".ignore-it/config.yml", defaultConfig) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.