rbgithook 0.1.1 → 0.1.3

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: 3f972f2dc37dc0d5ab6ee45fc28370053c0b987bb9e95f641e2a1f66ecdbc2e2
4
- data.tar.gz: 4b3ac378a6315e18e945e1ada3021955227415e3b2ec2b690f0cad4fb219bb29
3
+ metadata.gz: 126208371ad980b74efb9d3f90452e9ae9b05616d177a792e07c774e206f1f26
4
+ data.tar.gz: 98e3cff68de8a6946e00084e9d96fdeb1c7a329e6e8158c8b940ad3c6b6b8389
5
5
  SHA512:
6
- metadata.gz: 8f4b12920b3fa7c693baf53fe8f2a8669d72d35625b31fbdf9292bb7bc4d991c5c8e1208abfc8d84883afe5dd930f514e4fb0237a8ada1fe00e1be67dc07f9be
7
- data.tar.gz: b29b5234694d0f17c44493eaf0d61a9a82eb87c9376dc409314f1cfd5570e9c184285551fed027ee452fdf834fc9c576676c258ff8159c11f5b91e3b3e3bc829
6
+ metadata.gz: 101812bf06163703ea445fb781ccaf8457cb832ec36c37c98a7c978278232d28b12c9f4a5050d472f5d373bb10e3499865afbba7a28303dc87d93feec88752bf
7
+ data.tar.gz: cd6b654b1fba6548bc5453a885c60f8a24496cf09d35f308a6da5da0fa90c1cfff0d5233ddca7792a20e264e65b68835fff7b4a18708cbce8cd2f3b47823f952
data/.rubocop.yml CHANGED
@@ -15,5 +15,11 @@ Layout/LineLength:
15
15
  Style/FrozenStringLiteralComment:
16
16
  Enabled: false
17
17
 
18
+ Metrics/MethodLength:
19
+ Max: 30
20
+
21
+ Metrics/AbcSize:
22
+ Max: 30
23
+
18
24
  Style/Documentation:
19
25
  Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbgithook (0.1.1)
4
+ rbgithook (0.1.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ <img src="https://img.shields.io/github/license/hyuraku/rbgithook.svg"> <img src="https://img.shields.io/gem/v/rbgithook.svg">
1
2
  # Rbgithook
2
3
 
3
4
  Simple Git hook made by Ruby
data/Steepfile ADDED
@@ -0,0 +1,6 @@
1
+ target :lib do
2
+ signature "sig"
3
+
4
+ check "lib" # Directory name
5
+ library "fileutils"
6
+ end
data/exe/rbgithook CHANGED
@@ -1,13 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "rbgithook"
4
- require "fileutils"
5
4
 
6
5
  command = ARGV[0]
7
- args = ARGV[1..]
8
6
 
9
- if %w[add set].include?(command)
10
- Rbgithook.send(command, args)
11
- else
12
- Rbgithook.send(command)
7
+ if command.nil?
8
+ warn "Please specify a command to run\n\n"
9
+ Rbgithook.help
10
+ exit 1
13
11
  end
12
+
13
+ cmds = {
14
+ "install" => ->(_) { Rbgithook.install },
15
+ "set" => ->(args) { Rbgithook.set(args) },
16
+ "add" => ->(args) { Rbgithook.add(args) },
17
+ "uninstall" => ->(_) { Rbgithook.uninstall },
18
+ "help" => ->(_) { Rbgithook.help }
19
+ }
20
+
21
+ cmds.key?(command) ? cmds[command].call(ARGV[1..]) : Rbgithook.help
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rbgithook
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
data/lib/rbgithook.rb CHANGED
@@ -1,39 +1,77 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "rbgithook/version"
4
+ require "fileutils"
4
5
 
5
6
  module Rbgithook
7
+ DIRNAME = ".rbgithook"
8
+
6
9
  def self.install
7
- dir = ".rbgithook"
8
- FileUtils.mkdir(dir) unless Dir.exist?(dir)
10
+ FileUtils.mkdir(DIRNAME) unless Dir.exist?(DIRNAME)
9
11
 
10
- system("git", "config", "core.hooksPath", dir)
12
+ system("git", "config", "core.hooksPath", DIRNAME)
11
13
  end
12
14
 
13
15
  def self.set(args)
14
- file_name = args[0]
15
- hook_command = args[1]
16
- Dir.chdir(".rbgithook")
17
- file = File.open(file_name.to_s, "w")
18
- file.write("#!/usr/bin/env sh\n")
19
- file.write(hook_command)
16
+ file_name = get_file_name(args[0])
17
+ hook_command = get_hook_command(args[1])
18
+ Dir.chdir(DIRNAME)
19
+ File.open(file_name.to_s, "w") do |file|
20
+ file.write("#!/usr/bin/env sh\n#{hook_command}")
21
+ end
20
22
  FileUtils.chmod(0o755, file_name)
21
23
  end
22
24
 
23
25
  def self.add(args)
24
- file_name = args[0]
25
- hook_command = args[1]
26
- Dir.chdir(".rbgithook")
26
+ file_name = get_file_name(args[0])
27
+ hook_command = get_hook_command(args[1])
28
+ unless Dir.exist?(DIRNAME)
29
+ warning_message("Directory", file_name, hook_command)
30
+ exit 1
31
+ end
32
+ Dir.chdir(DIRNAME)
27
33
  if File.exist?(file_name)
28
- file = File.open(file_name.to_s, "a")
29
- file.write("\n#{hook_command}")
30
- FileUtils.chmod(0o755, file_name)
34
+ File.open(file_name.to_s, "a") do |file|
35
+ file.write("\n#{hook_command}")
36
+ end
31
37
  else
32
- warn "File not found, please run `rbgithook set #{file_name} #{hook_command}`"
38
+ warning_message("File", file_name, hook_command)
33
39
  end
34
40
  end
35
41
 
36
42
  def self.uninstall
37
43
  system("git", "config", "--unset", "core.hooksPath")
38
44
  end
45
+
46
+ def self.help
47
+ puts <<~USAGE
48
+ rbgithook [command] {file} {command}
49
+
50
+ install - Install hook
51
+ set {file} {command} - Set a hook
52
+ add {file} {command} - Add a hook
53
+ uninstall - Uninstall hook
54
+ help - Show this usage
55
+ USAGE
56
+ end
57
+
58
+ def self.warning_message(target, file_name, hook_command)
59
+ warn "#{target} not found, please run `rbgithook set #{file_name} '#{hook_command}'`"
60
+ end
61
+
62
+ def self.get_file_name(file_name)
63
+ if file_name.nil?
64
+ warn "Please specify a file to hook"
65
+ exit 1
66
+ end
67
+ file_name
68
+ end
69
+
70
+ def self.get_hook_command(hook_command)
71
+ if hook_command.nil?
72
+ warn "Please specify a command to run"
73
+ exit 1
74
+ end
75
+ hook_command
76
+ end
39
77
  end
data/sig/rbgithook.rbs ADDED
@@ -0,0 +1,16 @@
1
+ # TypeProf 0.21.3
2
+
3
+ # Classes
4
+ module Rbgithook
5
+ VERSION: String
6
+ DIRNAME: String
7
+
8
+ def self.install: -> void
9
+ def self.set: (Array[String] args) -> void
10
+ def self.add: (Array[String] args) -> void
11
+ def self.uninstall: -> void
12
+ def self.help: -> void
13
+ def self.warning_message: (String target, String file_name, String hook_command) -> void
14
+ def self.get_file_name: (String file_name) -> String
15
+ def self.get_hook_command: (String hook_command) -> String
16
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbgithook
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - hyuraku
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-05-25 00:00:00.000000000 Z
11
+ date: 2022-11-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple Git hook made by Ruby
14
14
  email:
@@ -27,10 +27,12 @@ files:
27
27
  - LICENSE.txt
28
28
  - README.md
29
29
  - Rakefile
30
+ - Steepfile
30
31
  - exe/rbgithook
31
32
  - lib/rbgithook.rb
32
33
  - lib/rbgithook/version.rb
33
34
  - rbgithook.gemspec
35
+ - sig/rbgithook.rbs
34
36
  homepage: https://github.com/hyuraku/rbgithook
35
37
  licenses:
36
38
  - MIT