sumire 24.03.30 → 24.03.31

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/exe/sumire +58 -27
  3. data/lib/sumire/version.rb +25 -1
  4. data/lib/sumire.rb +11 -10
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c16de0e198ae8999524f348b21c2795b12fbaadb35d889b4396e8ac7b3741ee9
4
- data.tar.gz: fac8e873d7eca4cbbbcb79533befddd719f34708b43ecce6390f28498b361764
3
+ metadata.gz: de68f31761206015fad844eb5b09054a51dc52edb88b1e72e9730f0889e95c56
4
+ data.tar.gz: 85395b3f6d1c7a2305f333718fbf7ff0753c4314940989af2bf62030c3078064
5
5
  SHA512:
6
- metadata.gz: e324b6edcef778c876ab4e9575bdca84828cac1fdd8a5c71aebf00cada46b00eca81f4f659430f8d732eda1e1d604da8a0a0bcdbc803daedb6ce309c9da9bacc
7
- data.tar.gz: 8fff912fd5b8f2f9bc30533de3db975d4488eadb48b3b27f07af12135a49854df125b272e6b06ff6012982d5b3d1aee157038d496b39ec27fb314d571e08ade2
6
+ metadata.gz: c05ba6d0cea2755c9c91ee86e1342d31a366ad8ef55f15d08647c3dd72e4e57e7d77268318437c9ea0a82db892f0e2f474af9b1e87edc14e4eb7b97b577d329f
7
+ data.tar.gz: 90da7a33132ed5b254e3bb146857a618d79ab6a27f3dfbb7ab9c8d6bd4649cd49210ec1c5602a0e91c5b36493b8da05d67d6d7077500f370b50e62f1beeb4f4b
data/exe/sumire CHANGED
@@ -5,6 +5,8 @@ require "sumire"
5
5
  require "listen"
6
6
  require "optparse"
7
7
  require "sys/proctable"
8
+ require "securerandom"
9
+ require "fileutils"
8
10
 
9
11
  @i18n = {
10
12
  "en": {
@@ -17,7 +19,10 @@ require "sys/proctable"
17
19
  "EOR": "\e[31;1m■ End of record\e[0m",
18
20
  "specify_dir": "Specify the directory",
19
21
  "no_directory": "\e[31mDirectory does not exist\e[0m",
20
- "save_to": "Save to: "
22
+ "save_to": "Save to: ",
23
+ "version_info": "Display version information",
24
+ "arg_command": "Run the command rather than an interactive shell",
25
+ "license_info": "Displays license information"
21
26
  },
22
27
  "ja": {
23
28
  "arg_less_one": "引数の個数は 1 個以下でなければなりません",
@@ -29,7 +34,10 @@ require "sys/proctable"
29
34
  "EOR": "\e[31;1m■ 記録を終了します\e[0m",
30
35
  "specify_dir": "ディレクトリを指定します",
31
36
  "no_directory": "\e[31mディレクトリが存在しません\e[0m",
32
- "save_to": "保存先: "
37
+ "save_to": "保存先: ",
38
+ "version_info": "バージョン情報を表示します",
39
+ "arg_command": "コマンドではなくシェルを実行します",
40
+ "license_info": "ソフトウェアのライセンス情報を表示します"
33
41
  }
34
42
  }
35
43
 
@@ -39,57 +47,80 @@ def comment(tag)
39
47
  @i18n[lang][tag]
40
48
  end
41
49
 
42
- def main(**kwargs) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
50
+ # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity, Lint/MissingCopEnableDirective
51
+ def main(**kwargs)
43
52
  dir = kwargs[:directory]
44
53
  dir = "." if dir.nil? || dir.empty?
45
54
  dir = dir.sub(%r{/\z}, "")
46
55
 
47
- processes = Sys::ProcTable.ps
48
- processes.each do |process|
49
- next unless process.cmdline.match(/^script/)
56
+ command = kwargs[:command]
57
+ command = command ? " -c \"#{command}\"" : ""
50
58
 
51
- warn("#{comment(:exist_process)}\n\n")
52
- warn("\e[32mkill #{process.pid}\e[0m")
53
- exit(false)
59
+ verbose = kwargs[:verbose] || false
60
+
61
+ unless verbose
62
+ processes = Sys::ProcTable.ps
63
+ processes.each do |process|
64
+ next unless process.cmdline.match(/^script/)
65
+
66
+ warn("#{comment(:exist_process)}\n\n")
67
+ warn("\e[32mkill #{process.pid}\e[0m")
68
+ exit(false)
69
+ end
54
70
  end
55
71
 
72
+ dst = "#{dir}/#{Time.now.strftime("%Y%m%d_%H%M%S")}.log"
73
+ dst = File.expand_path(dst)
56
74
  print(comment(:save_to))
57
- puts("#{dir}/#{Time.now.strftime("%Y%m%d_%H%M%S")}.log")
75
+ puts(dst)
58
76
  puts(comment(:start_recording))
59
- system("sumire -m #{dir}& script -f")
77
+
78
+ FileUtils.mkdir_p("/tmp/sumire")
79
+ tmp = "/tmp/sumire/#{SecureRandom.uuid}.log"
80
+ tmp = Pathname(Dir.pwd).join("typescript").to_path if verbose
81
+ thread = Thread.new do
82
+ Sumire::Sumire.exec(destination: dst, target: tmp, verbose: verbose)
83
+ end
84
+ thread.join if verbose
85
+
86
+ script_cmd = "script -f #{tmp}#{command}"
87
+ system(script_cmd) unless verbose
88
+
60
89
  puts(comment(:EOR))
61
90
  end
62
91
 
63
92
  opt = OptionParser.new
93
+ verbose = false
94
+ dir = "."
95
+ cmd = nil
64
96
 
65
- opt.on("-v", "--verbose", comment(:output_log)) do |_v|
66
- Sumire::Sumire.exec(verbose: true)
97
+ opt.on("-V", "--version", comment(:version_info)) do |_v|
98
+ puts("#{File.basename($PROGRAM_NAME)} (#{Sumire::VERSION})")
67
99
  exit(true)
68
100
  end
69
101
 
70
- opt.on("-m [Directory]", "--monitor", comment(:save_log)) do |dir|
71
- Sumire::Sumire.exec(directory: dir)
102
+ opt.on("--license", comment(:license_info)) do |_v|
103
+ puts(Sumire::COPYRIGHT)
72
104
  exit(true)
73
105
  end
74
106
 
75
- opt.on("-d [Directory]", "--directory [Directory]", comment(:specify_dir)) do |dir|
76
- if dir.nil?
77
- dir = ""
78
- elsif !Dir.exist?(dir)
79
- warn(comment(:no_directory))
80
- exit(false)
81
- end
82
- main(directory: dir)
83
- exit(true)
107
+ opt.on("-v", "--verbose", comment(:output_log)) do |v|
108
+ verbose = v
84
109
  end
85
110
 
86
- opt.on("") do |_v|
87
- main
88
- exit(true)
111
+ opt.on("-c [Command]", "--command", comment(:arg_command)) do |command|
112
+ cmd = command
113
+ end
114
+
115
+ opt.on("-d [Directory]", "--directory", comment(:specify_dir)) do |directory|
116
+ dir = directory
89
117
  end
90
118
 
91
119
  begin
92
120
  opt.parse!(ARGV)
93
121
  rescue OptionParser::InvalidOption
94
122
  warn(comment(:option_not_appropriate))
123
+ exit(false)
95
124
  end
125
+
126
+ main(directory: dir, verbose: verbose, command: cmd)
@@ -1,5 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sumire
4
- VERSION = "24.03.30"
4
+ VERSION = "24.03.31"
5
+
6
+ COPYRIGHT = <<~COPYRIGHT_TEXT
7
+ The MIT License (MIT)
8
+
9
+ Copyright (c) 2024 MURATA Mitsuharu
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in
19
+ all copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27
+ THE SOFTWARE.
28
+ COPYRIGHT_TEXT
5
29
  end
data/lib/sumire.rb CHANGED
@@ -2,30 +2,31 @@
2
2
 
3
3
  require_relative "sumire/version"
4
4
  require "ansi2txt"
5
+ require "fileutils"
5
6
 
6
7
  module Sumire
7
8
  class Error < StandardError; end
8
9
 
9
10
  class Sumire # rubocop:disable Style/Documentation
10
- class << self
11
- attr_accessor :directory
12
- end
13
-
14
11
  # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity, Lint/MissingCopEnableDirective
15
12
  def self.exec(**kwargs)
16
- directory = kwargs[:directory]
17
- directory = "." if directory.nil?
13
+ destination = kwargs[:destination]
14
+ if destination.nil?
15
+ FileUtils.mkdir_p("/tmp/sumire")
16
+ destination = "/tmp/sumire/#{SecureRandom.uuid}.log"
17
+ end
18
18
  target = kwargs[:target]
19
19
  target = "typescript" if target.nil?
20
20
  verbose = kwargs[:verbose] || false
21
21
  old_lines = 0
22
22
  list = []
23
23
  old_text = ""
24
- start_time = Time.now.strftime("%Y%m%d_%H%M%S")
24
+
25
+ listen_dir = File.dirname(target)
25
26
 
26
27
  # rubocop:disable Metrics/BlockLength
27
- listener = Listen.to(".") do |modified, _added, _removed|
28
- if modified.map { |file| File.basename(file) }.include?(target)
28
+ listener = Listen.to(listen_dir) do |modified, _added, _removed|
29
+ if modified.include?(target)
29
30
  input = File.open(target)
30
31
 
31
32
  # txt: string
@@ -54,7 +55,7 @@ module Sumire
54
55
  if old_lines < new_lines
55
56
  add_line.each do |line|
56
57
  list.append(line)
57
- File.open("#{directory}/#{start_time}.log", "a") do |f|
58
+ File.open(destination, "a") do |f|
58
59
  f.puts(line)
59
60
  end
60
61
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sumire
3
3
  version: !ruby/object:Gem::Version
4
- version: 24.03.30
4
+ version: 24.03.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - MURATA Mitsuharu