zoi 0.0.1 → 0.1.0

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: 2ccfa9bd2af8d9ab31bbdc514297d9365c38bc2421b2173093fe08fd8251d944
4
- data.tar.gz: ba885cd33410899947a601f53750527d40099859bbd505e2f6950c47da6e447f
3
+ metadata.gz: dcf9ada58a6c4d261304bf85581a811ca84745c1820e7f08e1141cb11f1605d8
4
+ data.tar.gz: e3edf9ec712d10b3edc73b299d5144c1d6befd3e1d25810467ef5cffaf26577f
5
5
  SHA512:
6
- metadata.gz: 595012ed030fcaafc09abffb41e3f02632c3249676ba14384abcf37a032709c2a2eabc39d2b4931a8ca2dbed10949d285dc3a93f4d905152c3ac85dae9e5938d
7
- data.tar.gz: f1a8b96908b12885b34697ab56580e08d81c4b51fdd3923c0cd132776b1f3531a512dc8ee5a213319fb5be4fb836f145b8212260df19c96392094582c46b421a
6
+ metadata.gz: 572cf635f41310c624aa38ae43dbe1b34cdf10830bcadc7367334eb463806ffc2783e847f60a5929d5014d2f7ccba895f99c37ffc751e5b676213b5b2c630e9e
7
+ data.tar.gz: ca5cfb874c5e37f3028b114b5d6c77141d9a0de891f833dca34db903df10d6d10915849a49e413e2d662d9be14427e3c9bb45200fa5a61e395027483ae834f89
@@ -0,0 +1,21 @@
1
+ name: Ruby
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ matrix:
9
+ os: [macos-latest, ubuntu-latest]
10
+ ruby: [2.7, 3.0]
11
+ runs-on: ${{ matrix.os }}
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby
15
+ uses: ruby/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install dependencies
19
+ run: bundle install
20
+ - name: Run tests
21
+ run: ruby test/*.rb
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  Gemfile.lock
2
2
  pkg
3
+ tmp/
data/CHANGELOG.adoc ADDED
@@ -0,0 +1,4 @@
1
+ == 0.1.0 (July 7, 2021)
2
+
3
+ === Enhancements
4
+ * Add basic commands https://github.com/9sako6/zoi/pull/2[#2]
data/Gemfile CHANGED
@@ -1,7 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
4
6
 
7
+ gem 'thor'
8
+
5
9
  group :development do
6
10
  gem 'rake', '~> 12.0'
7
11
  end
12
+
13
+ group :test do
14
+ gem 'mocha'
15
+ end
data/README.adoc ADDED
@@ -0,0 +1,58 @@
1
+ = zoi(1)
2
+
3
+ == NAME
4
+
5
+ zoi - Manage snippets
6
+
7
+ == DESCRIPTION
8
+
9
+ Manage snippets.
10
+
11
+ [verse]
12
+ zoi c ruby/foo.rb
13
+ # ~/zoi/ruby/foo.rb is created.
14
+
15
+ == SYNOPSIS
16
+
17
+ [verse]
18
+ zoi create <filepath>
19
+ zoi open <filepath>
20
+ zoi list [-d]
21
+ zoi root
22
+ zoi help
23
+
24
+ == COMMANDS
25
+
26
+ create::
27
+ Create a new file under zoi root directory. If the file already exists, the file isn't created. +
28
+ In all cases, the full path of the file is printed to stdout.
29
+
30
+ open::
31
+ Execute `create` command and open the file with the editor specified by `$EDITOR`. For example: `EDITOR=code zoi open foobar.rb`
32
+
33
+ list::
34
+ List all files under zoi root directory. +
35
+ With '-d' option, list all directories under zoi root directory.
36
+
37
+ root::
38
+ Print zoi root directory.
39
+
40
+ help::
41
+ Print a brief help message.
42
+
43
+ == INSTALLATION
44
+
45
+ gem install zoi
46
+
47
+ == EXAMPLES
48
+
49
+ Open today's memo file in VSCode.
50
+
51
+ [verse]
52
+ code $(date "+%Y%m%d.adoc" | zoi c)
53
+
54
+ A new file ~/zoi/20210727.adoc is created and is opend in VSCode.
55
+
56
+ == AUTHOR
57
+
58
+ https://github.com/9sako6[9sako6]
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rspec/core/rake_task'
3
5
 
data/exe/zoi CHANGED
@@ -1,13 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require 'zoi'
4
5
 
5
- case ARGV[0]
6
- when '-l', '--list'
7
- puts Zoi.list
8
- when '-t', '--today'
9
- puts Zoi.today_file
10
- when nil
11
- new_file_path = Zoi.create
12
- new_file_path.nil? ? nil : (puts new_file_path)
13
- end
6
+ args = File.pipe?(STDIN) ? ARGV + STDIN.gets.chomp.split : ARGV
7
+
8
+ Zoi::CLI.start(args)
data/lib/zoi.rb CHANGED
@@ -1,43 +1,6 @@
1
- require 'date'
2
- require 'fileutils'
3
- require_relative 'zoi/version'
4
-
5
- module Zoi
6
- class Error < StandardError; end
7
-
8
- class << self
9
- def create
10
- FileUtils.mkdir_p(root_path)
11
-
12
- return if File.exist?(today_file)
13
-
14
- File.open(today_file, 'w') do |f|
15
- f.puts "# #{today}"
16
- end
17
-
18
- today_file
19
- end
1
+ # frozen_string_literal: true
20
2
 
21
- def list
22
- Dir.glob("#{root_path}/*")
23
- end
24
-
25
- def today_file
26
- File.join(root_path, file_name)
27
- end
28
-
29
- private
30
-
31
- def file_name
32
- "#{today}.md"
33
- end
34
-
35
- def today
36
- Date.today.strftime('%Y%m%d')
37
- end
3
+ require_relative 'zoi/version'
4
+ require_relative 'zoi/cli.rb'
38
5
 
39
- def root_path
40
- File.join(Dir.home, name.downcase)
41
- end
42
- end
43
- end
6
+ module Zoi; end
data/lib/zoi/cli.rb ADDED
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'find'
5
+ require 'open3'
6
+ require 'thor'
7
+
8
+ module Zoi
9
+ ROOT_DIR_NAME = 'zoi'
10
+
11
+ class CLI < Thor
12
+ desc 'create <filepath>', 'Create a new file under zoi root directory.'
13
+ def create(file_path)
14
+ return if file_path.nil?
15
+
16
+ puts create_file(file_path)
17
+ end
18
+
19
+ desc 'open <filepath>', 'Execute `create` command and open the file with the editor specified by $EDITOR. For example: `EDITOR=code zoi open foobar.rb`'
20
+ def open(file_path)
21
+ return if editor.nil? || file_path.nil?
22
+
23
+ created_file_path = create_file(file_path)
24
+
25
+ puts created_file_path
26
+
27
+ open_file(created_file_path)
28
+ end
29
+
30
+ desc 'list [-d]', 'List all files under zoi root directory.'
31
+ option 'd', type: :boolean
32
+ def list
33
+ only_directory = options['d']
34
+
35
+ puts(Find.find(root_path).select { |path| only_directory ? File.directory?(path) : File.file?(path) })
36
+ end
37
+
38
+ no_tasks do
39
+ def editor
40
+ @editor ||= ENV['EDITOR']
41
+ end
42
+
43
+ def create_file(file_path)
44
+ file_full_path = File.join(root_path, file_path)
45
+
46
+ return file_full_path if File.exist?(file_full_path)
47
+
48
+ dir_path = File.join(root_path, File.dirname(file_path))
49
+
50
+ FileUtils.mkdir_p(dir_path)
51
+ FileUtils.touch(file_full_path)
52
+ file_full_path
53
+ end
54
+
55
+ def open_file(file_path)
56
+ system(editor, file_path)
57
+ end
58
+
59
+ def root_path
60
+ @root_path ||= Pathname(Dir.home).join(ROOT_DIR_NAME).to_s
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/zoi/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Zoi
2
- VERSION = '0.0.1'.freeze
4
+ VERSION = '0.1.0'
3
5
  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.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 9sako6
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-26 00:00:00.000000000 Z
11
+ date: 2021-07-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: management snippets
14
14
  email:
@@ -18,16 +18,16 @@ executables:
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".github/workflows/test.yml"
21
22
  - ".gitignore"
22
- - CHANGELOG.md
23
+ - CHANGELOG.adoc
23
24
  - Gemfile
24
25
  - LICENSE
25
- - README.md
26
+ - README.adoc
26
27
  - Rakefile
27
- - bin/console
28
- - bin/setup
29
28
  - exe/zoi
30
29
  - lib/zoi.rb
30
+ - lib/zoi/cli.rb
31
31
  - lib/zoi/version.rb
32
32
  - zoi.gemspec
33
33
  homepage: https://github.com/9sako6/zoi
data/CHANGELOG.md DELETED
File without changes
data/README.md DELETED
@@ -1,35 +0,0 @@
1
- # Zoi
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zoi`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'zoi'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install zoi
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zoi.
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'zoi'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require 'irb'
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here