zoi 0.1.2 → 0.1.5

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: 16c4626ef7751aeebc5de4ca21e43ee40f74db06e9b0afc885ef8f7da70f38ea
4
- data.tar.gz: 1c59a8d91bf0ea8a70e70faff929525ed255ddf91548e8973fa662057c1ae1f0
3
+ metadata.gz: 2c66fdddee8d9cf4c04ae744033d4bd5d50993bfde2bbbdd1875991243afe99b
4
+ data.tar.gz: bc77049d0e91608bdea93c0455a5cbcca4b8030ba4a945bf5f05cc979e58897c
5
5
  SHA512:
6
- metadata.gz: d599df9fab552398bfa4022a540fe5af4b6d6f87ae606758562e66aa7e6f1a26f69b28b059fc9d4449a4f8d0c39a91a0554d39d89d2f37a034aa56dc94e1ac18
7
- data.tar.gz: d70f7e0232ebecc595227821f1b2d3ea05828430595e1ca287c33c4c880bdbe4ba12ac8c1adf0440335a1ac55574c5c96404253c857195622cd38946c953e4da
6
+ metadata.gz: aeeb78165262b8cb11cae553007172d6c8baa1066b461a5e7683321a4f26e758270825375235ae238af0af8d09c1c754fbfbcb2ead5d406eb1f15ad1f7ee3061
7
+ data.tar.gz: 935fdfd8dd33edca57db92e93e00c946c61a576c1c1ed27ef4f0aa4f867b12ffe00e75bbc17fda0a75dcd4e86849c0acd8d5e9dc582a62aa9b92e91225a61e7d
@@ -17,5 +17,7 @@ jobs:
17
17
  ruby-version: ${{ matrix.ruby }}
18
18
  - name: Install dependencies
19
19
  run: bundle install
20
+ - name: RuboCop
21
+ run: rake rubocop
20
22
  - name: Run tests
21
- run: ruby test/*.rb
23
+ run: rake test
data/.rubocop.yml ADDED
@@ -0,0 +1,2 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
data/CHANGELOG.adoc CHANGED
@@ -1,4 +1,31 @@
1
- == 0.1.1 (September 11, 2021)
1
+ == 0.1.5 (April 12, 2022)
2
+
3
+ === Enhancements
4
+ * Add `version` command
5
+
6
+ == 0.1.4 (January 6, 2022)
7
+
8
+ === Enhancements
9
+ * Add a configuration file, __~/.zoirc.json__ https://github.com/9sako6/zoi/pull/17[#17]
10
+ ** You can optionally save the settings used by zoi to a configuration file, __~/.zoirc.json__. +
11
+ The type of editor used by zoi can be specified in the __~/.zoirc.json__ file. +
12
+ The following is the example of the __~/.zoirc.json__ file.
13
+ +
14
+ [source,json]
15
+ ----
16
+ {
17
+ "editor": "code"
18
+ }
19
+ ----
20
+ +
21
+ In that case, there is no need to pass the `EDITOR` environment variable at runtime.
22
+
23
+ == 0.1.3 (September 15, 2021)
24
+
25
+ === Enhancements
26
+ * Add `memo` command https://github.com/9sako6/zoi/pull/11[#11]
27
+
28
+ == 0.1.2 (September 11, 2021)
2
29
 
3
30
  === Enhancements
4
31
  * Add `root` command https://github.com/9sako6/zoi/pull/8[#8]
data/Gemfile CHANGED
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- source 'https://rubygems.org'
3
+ source "https://rubygems.org"
4
4
 
5
5
  gemspec
6
6
 
7
- gem 'thor'
7
+ gem "thor"
8
8
 
9
9
  group :development do
10
- gem 'rake', '~> 12.0'
10
+ gem "rake", "~> 12.0"
11
+ gem "rubocop-shopify", require: false
11
12
  end
12
13
 
13
14
  group :test do
14
- gem 'mocha'
15
+ gem "mocha"
16
+ gem "timecop"
15
17
  end
data/README.adoc CHANGED
@@ -18,6 +18,7 @@ zoi create ruby/foo.rb
18
18
  zoi create <filepath>
19
19
  zoi open <filepath>
20
20
  zoi list [-d]
21
+ zoi memo
21
22
  zoi root
22
23
  zoi help
23
24
 
@@ -36,6 +37,12 @@ list::
36
37
  List all files under zoi root directory. +
37
38
  With '-d' option, list all directories under zoi root directory.
38
39
 
40
+ memo::
41
+ Create today's memo file and open the file with the editor specified by `$EDITOR`. +
42
+ The file name is `YYYY-MM-DD.md` +
43
+ For example: `EDITOR=code zoi open memo/20210101.md` +
44
+ If it's September 9th in 2021, a new file ~/zoi/2021-09-09.md is created and is opend with the VSCode editor.
45
+
39
46
  root::
40
47
  Print zoi root directory.
41
48
 
@@ -46,14 +53,24 @@ help::
46
53
 
47
54
  gem install zoi
48
55
 
49
- == EXAMPLES
56
+ == CONFIGURATION
50
57
 
51
- * Open today's memo file in VSCode.
52
- +
53
- [verse]
54
- date "+%Y%m%d.adoc" | EDITOR=code zoi open
55
- +
56
- A new file ~/zoi/20210727.adoc is created and is opend in VSCode.
58
+ You can optionally save the settings used by zoi to a configuration file, __~/.zoirc.json__.
59
+
60
+ The type of editor used by zoi can be specified in the __~/.zoirc.json__ file.
61
+
62
+ The following is the example of the __~/.zoirc.json__ file.
63
+
64
+ [source,json]
65
+ ----
66
+ {
67
+ "editor": "code"
68
+ }
69
+ ----
70
+
71
+ In that case, there is no need to pass the `EDITOR` environment variable at runtime.
72
+
73
+ == EXAMPLES
57
74
 
58
75
  * Change directories
59
76
  +
data/Rakefile CHANGED
@@ -1,8 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
5
6
 
6
- RSpec::Core::RakeTask.new(:spec)
7
+ task default: [:"rubocop:auto_correct", :test]
7
8
 
8
- task default: :spec
9
+ Rake::TestTask.new do |test|
10
+ test.test_files = FileList["./test/*.rb"]
11
+ # Display detail information.
12
+ test.verbose = true
13
+ end
14
+
15
+ RuboCop::RakeTask.new
data/exe/zoi CHANGED
@@ -1,8 +1,10 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'zoi'
4
+ require "zoi"
5
5
 
6
- args = File.pipe?(STDIN) ? ARGV + STDIN.gets.chomp.split : ARGV
6
+ args = File.pipe?($stdin) ? ARGV + $stdin.gets.chomp.split : ARGV
7
+
8
+ ENV["THOR_SILENCE_DEPRECATION"] = "true"
7
9
 
8
10
  Zoi::CLI.start(args)
data/lib/zoi/cli.rb CHANGED
@@ -1,23 +1,34 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'fileutils'
4
- require 'find'
5
- require 'open3'
6
- require 'pathname'
7
- require 'thor'
3
+ require "date"
4
+ require "fileutils"
5
+ require "find"
6
+ require "json"
7
+ require "open3"
8
+ require "pathname"
9
+ require "thor"
8
10
 
9
11
  module Zoi
10
- ROOT_DIR_NAME = 'zoi'
12
+ ROOT_DIR_NAME = "zoi"
13
+ CONFIG_FILE_NAME = ".zoirc.json"
11
14
 
12
15
  class CLI < Thor
13
- desc 'create <filepath>', 'Create a new file under zoi root directory.'
16
+ desc "version", "Show version."
17
+ def version
18
+ puts Zoi::VERSION
19
+ end
20
+
21
+ desc "create <filepath>", "Create a new file under zoi root directory."
14
22
  def create(file_path)
15
23
  return if file_path.nil?
16
24
 
17
25
  puts create_file(file_path)
18
26
  end
19
27
 
20
- desc 'open <filepath>', 'Execute `create` command and open the file with the editor specified by $EDITOR. For example: `EDITOR=code zoi open foobar.rb`'
28
+ desc "open <filepath>", <<~DESCRIPTION
29
+ Execute `create` command and open the file with the editor specified by $EDITOR.
30
+ For example: `EDITOR=code zoi open foobar.rb`
31
+ DESCRIPTION
21
32
  def open(file_path)
22
33
  return if editor.nil? || file_path.nil?
23
34
 
@@ -28,26 +39,41 @@ module Zoi
28
39
  open_file(created_file_path)
29
40
  end
30
41
 
31
- desc 'list [-d]', 'List all files under zoi root directory.'
32
- option 'd', type: :boolean
42
+ desc "list [-d]", "List all files under zoi root directory."
43
+ option "d", type: :boolean
33
44
  def list
34
- only_directory = options['d']
45
+ only_directory = options["d"]
35
46
 
36
47
  puts(Find.find(root_path).select { |path| only_directory ? File.directory?(path) : File.file?(path) })
37
48
  end
38
49
 
39
- desc 'root', 'Print zoi root directory.'
50
+ desc "memo", "Create today's memo file and open the file with the editor specified by `$EDITOR`."
51
+ def memo
52
+ return if editor.nil?
53
+
54
+ created_file_path = create_file("#{Date.today}.md")
55
+
56
+ puts created_file_path
57
+
58
+ open_file(created_file_path)
59
+ end
60
+
61
+ desc "root", "Print zoi root directory."
40
62
  def root_command
41
63
  puts root_path
42
64
  end
43
65
 
44
66
  # NOTE: Resolve the following error.
45
67
  # `"root" is a Thor reserved word and cannot be defined as command`
46
- map 'root' => 'root_command'
68
+ map "root" => "root_command"
47
69
 
48
70
  no_tasks do
49
71
  def editor
50
- @editor ||= ENV['EDITOR']
72
+ if File.exist?(config_file_path)
73
+ load_envs_from_config_file
74
+ end
75
+
76
+ ENV["EDITOR"]
51
77
  end
52
78
 
53
79
  def create_file(file_path)
@@ -69,6 +95,18 @@ module Zoi
69
95
  def root_path
70
96
  @root_path ||= Pathname(Dir.home).join(ROOT_DIR_NAME).to_s
71
97
  end
98
+
99
+ def config_file_path
100
+ @config_file_path ||= Pathname(Dir.home).join(CONFIG_FILE_NAME).to_s
101
+ end
102
+
103
+ def config_json
104
+ @config_json ||= JSON.parse(File.open(config_file_path, "r", &:read))
105
+ end
106
+
107
+ def load_envs_from_config_file
108
+ ENV["EDITOR"] = config_json["editor"] unless ENV["EDITOR"]
109
+ end
72
110
  end
73
111
  end
74
112
  end
data/lib/zoi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zoi
4
- VERSION = '0.1.2'
4
+ VERSION = "0.1.5"
5
5
  end
data/lib/zoi.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'zoi/version'
4
- require_relative 'zoi/cli.rb'
3
+ require_relative "zoi/version"
4
+ require_relative "zoi/cli"
5
5
 
6
6
  module Zoi; end
data/zoi.gemspec CHANGED
@@ -1,28 +1,28 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/zoi/version'
3
+ require_relative "lib/zoi/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = 'zoi'
6
+ spec.name = "zoi"
7
7
  spec.version = Zoi::VERSION
8
- spec.authors = ['9sako6']
9
- spec.email = ['31821663+9sako6@users.noreply.github.com']
8
+ spec.authors = ["9sako6"]
9
+ spec.email = ["31821663+9sako6@users.noreply.github.com"]
10
10
 
11
- spec.summary = 'management snippets'
12
- spec.description = 'management snippets'
13
- spec.homepage = 'https://github.com/9sako6/zoi'
14
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
11
+ spec.summary = "management snippets"
12
+ spec.description = "management snippets"
13
+ spec.homepage = "https://github.com/9sako6/zoi"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
15
15
 
16
- spec.metadata['homepage_uri'] = spec.homepage
17
- spec.metadata['source_code_uri'] = 'https://github.com/9sako6/zoi'
18
- spec.metadata['changelog_uri'] = 'https://github.com/9sako6/zoi'
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = "https://github.com/9sako6/zoi"
18
+ spec.metadata["changelog_uri"] = "https://github.com/9sako6/zoi"
19
19
 
20
20
  # Specify which files should be added to the gem when it is released.
21
21
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
22
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
23
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
24
  end
25
- spec.bindir = 'exe'
25
+ spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
- spec.require_paths = ['lib']
27
+ spec.require_paths = ["lib"]
28
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zoi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 9sako6
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-11 00:00:00.000000000 Z
11
+ date: 2022-04-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: management snippets
14
14
  email:
@@ -20,6 +20,7 @@ extra_rdoc_files: []
20
20
  files:
21
21
  - ".github/workflows/test.yml"
22
22
  - ".gitignore"
23
+ - ".rubocop.yml"
23
24
  - CHANGELOG.adoc
24
25
  - Gemfile
25
26
  - LICENSE