rbgithook 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f972f2dc37dc0d5ab6ee45fc28370053c0b987bb9e95f641e2a1f66ecdbc2e2
4
- data.tar.gz: 4b3ac378a6315e18e945e1ada3021955227415e3b2ec2b690f0cad4fb219bb29
3
+ metadata.gz: c71ca6cde42b02269ac1aeee9e663bb5b516b2fdecc66d79431b44d1562ad996
4
+ data.tar.gz: 9b7eb15086882d290128c30e49a127d419957a2eb23868de0611e31cf8d52879
5
5
  SHA512:
6
- metadata.gz: 8f4b12920b3fa7c693baf53fe8f2a8669d72d35625b31fbdf9292bb7bc4d991c5c8e1208abfc8d84883afe5dd930f514e4fb0237a8ada1fe00e1be67dc07f9be
7
- data.tar.gz: b29b5234694d0f17c44493eaf0d61a9a82eb87c9376dc409314f1cfd5570e9c184285551fed027ee452fdf834fc9c576676c258ff8159c11f5b91e3b3e3bc829
6
+ metadata.gz: 28ec92618c41e81d9f6170fc708ef2299b2bcfc923efe20cdf0975dcc52ea5cac28da7f95601cec30146a81fe7f1356c17d4ecda2508bd7332a67e1e6040771f
7
+ data.tar.gz: 4a027d02efb93afcd777733bb8feb2ce67a2e40a63ce22009d7bf567525fb382cff94c3f82a026324146790131cf04f0835daaa6a5e5a62f157debe0eb9c1fcb
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.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/exe/rbgithook CHANGED
@@ -4,10 +4,19 @@ require "rbgithook"
4
4
  require "fileutils"
5
5
 
6
6
  command = ARGV[0]
7
- args = ARGV[1..]
8
7
 
9
- if %w[add set].include?(command)
10
- Rbgithook.send(command, args)
11
- else
12
- Rbgithook.send(command)
8
+ if command.nil?
9
+ warn "Please specify a command to run\n\n"
10
+ Rbgithook.help
11
+ exit 1
13
12
  end
13
+
14
+ cmds = {
15
+ "install" => ->(_) { Rbgithook.install },
16
+ "set" => ->(args) { Rbgithook.set(args) },
17
+ "add" => ->(args) { Rbgithook.add(args) },
18
+ "uninstall" => ->(_) { Rbgithook.uninstall },
19
+ "help" => ->(_) { Rbgithook.help }
20
+ }
21
+
22
+ 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.2"
5
5
  end
data/lib/rbgithook.rb CHANGED
@@ -12,28 +12,63 @@ module Rbgithook
12
12
 
13
13
  def self.set(args)
14
14
  file_name = args[0]
15
+ if file_name.nil?
16
+ warn "Please specify a file to hook"
17
+ exit 1
18
+ end
15
19
  hook_command = args[1]
20
+ if hook_command.nil?
21
+ warn "Please specify a command to run"
22
+ exit 1
23
+ end
16
24
  Dir.chdir(".rbgithook")
17
25
  file = File.open(file_name.to_s, "w")
18
- file.write("#!/usr/bin/env sh\n")
19
- file.write(hook_command)
26
+ file.write("#!/usr/bin/env sh\n#{hook_command}")
20
27
  FileUtils.chmod(0o755, file_name)
21
28
  end
22
29
 
23
30
  def self.add(args)
24
31
  file_name = args[0]
32
+ if file_name.nil?
33
+ warn "Please specify a file to hook"
34
+ exit 1
35
+ end
25
36
  hook_command = args[1]
26
- Dir.chdir(".rbgithook")
37
+ if hook_command.nil?
38
+ warn "Please specify a command to run"
39
+ exit 1
40
+ end
41
+ dir_name = ".rbgithook"
42
+ unless Dir.exist?(dir_name)
43
+ warning_message("Directory", file_name, hook_command)
44
+ exit 1
45
+ end
46
+ Dir.chdir(dir_name)
27
47
  if File.exist?(file_name)
28
48
  file = File.open(file_name.to_s, "a")
29
49
  file.write("\n#{hook_command}")
30
- FileUtils.chmod(0o755, file_name)
31
50
  else
32
- warn "File not found, please run `rbgithook set #{file_name} #{hook_command}`"
51
+ warning_message("File", file_name, hook_command)
33
52
  end
34
53
  end
35
54
 
36
55
  def self.uninstall
37
56
  system("git", "config", "--unset", "core.hooksPath")
38
57
  end
58
+
59
+ def self.help
60
+ puts <<~USAGE
61
+ bgithook [command] {file} {command}
62
+
63
+ install - Install hook
64
+ set {file} {command} - Set a hook
65
+ add {file} {command} - Add a hook
66
+ uninstall - Uninstall hook
67
+ help - Show this usage
68
+ USAGE
69
+ end
70
+
71
+ def self.warning_message(target, file_name, hook_command)
72
+ warn "#{target} not found, please run `rbgithook set #{file_name} '#{hook_command}'`"
73
+ end
39
74
  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.2
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-06-14 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple Git hook made by Ruby
14
14
  email: