dev_oops 0.1.1 → 0.2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test_and_publish.yml +58 -0
- data/.github/workflows/test_only.yml +37 -0
- data/.github/workflows/verify_version_change.yml +21 -0
- data/.rubocop.yml +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +32 -0
- data/README.md +93 -13
- data/Rakefile +0 -3
- data/bin/local_do +7 -0
- data/dev_oops.gemspec +27 -15
- data/lib/dev_oops.rb +7 -156
- data/lib/dev_oops/commands/edit_script.rb +19 -0
- data/lib/dev_oops/commands/edit_script_sh.rb +16 -0
- data/lib/dev_oops/commands/remove_script.rb +18 -0
- data/lib/dev_oops/runner.rb +56 -0
- data/lib/dev_oops/scripts_loader.rb +63 -0
- data/lib/dev_oops/version.rb +1 -1
- metadata +100 -6
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32ee75a41461d7793d454367ce09a989c796df9a50c861d27795a5864e74a9ca
|
4
|
+
data.tar.gz: 0351c14d9116a45119a773c69fd1dc493837a48b06366d3b4a2977c34428673a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 989bb33a56ad674bdfc1a47719648b5111668af45d160c2e971113ca56ccc7dc27c8862962b7c9cae20700f3c2b6e5ff3853239f6a621c96afe066c2871ddc70
|
7
|
+
data.tar.gz: 4f967de470975239f896074dea2bf86869647dd3d0f3820f503a0e195539446f99b3e0cdcbc5b5143a884889e4944e20d8d94a07c51a39db1c45a5a14affe1eb
|
@@ -0,0 +1,58 @@
|
|
1
|
+
name: Test and Release
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
tests:
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: [2.6, 2.7, 3.0]
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Run linter
|
23
|
+
run: bundle exec rubocop
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rspec
|
26
|
+
prettier:
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v2
|
30
|
+
- name: Set up Node
|
31
|
+
uses: actions/setup-node@v2
|
32
|
+
with:
|
33
|
+
node-version: '14'
|
34
|
+
- name: Install yarn dep
|
35
|
+
run: yarn install
|
36
|
+
- name: Check prettier
|
37
|
+
run: yarn prettier -c '**/*.rb'
|
38
|
+
release:
|
39
|
+
needs: [tests, prettier]
|
40
|
+
runs-on: ubuntu-latest
|
41
|
+
|
42
|
+
steps:
|
43
|
+
- uses: actions/checkout@v2
|
44
|
+
- name: Set up Ruby
|
45
|
+
uses: ruby/setup-ruby@v1
|
46
|
+
with:
|
47
|
+
ruby-version: 3.0
|
48
|
+
bundler-cache: true
|
49
|
+
- name: Prepare credentials
|
50
|
+
env:
|
51
|
+
RUBYGEM_KEY: ${{ secrets.RUBYGEM_KEY }}
|
52
|
+
run: "mkdir -p ~/.gem && echo -e \"---\\r\\n:rubygems_api_key: $RUBYGEM_KEY\" > ~/.gem/credentials && chmod 0600 ~/.gem/credentials"
|
53
|
+
- name: Setup username/email
|
54
|
+
run: "git config --global user.email zaratan@hey.com && git config --global user.name \"Denis <Zaratan> Pasin\""
|
55
|
+
- name: Fetch tags from remote
|
56
|
+
run: "git fetch -t"
|
57
|
+
- name: Publish if version change
|
58
|
+
run: 'git diff `git tag | tail -1` -- lib/dev_oops/version.rb | grep -E "^\+.*VERSION" && rake release || echo "No release for now"'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: Tests
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches-ignore:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
tests:
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby: [2.6, 2.7, 3.0]
|
13
|
+
runs-on: ubuntu-latest
|
14
|
+
|
15
|
+
steps:
|
16
|
+
- uses: actions/checkout@v2
|
17
|
+
- name: Set up Ruby
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
bundler-cache: true
|
22
|
+
- name: Run linter
|
23
|
+
run: bundle exec rubocop
|
24
|
+
- name: Run tests
|
25
|
+
run: bundle exec rspec
|
26
|
+
prettier:
|
27
|
+
runs-on: ubuntu-latest
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@v2
|
30
|
+
- name: Set up Node
|
31
|
+
uses: actions/setup-node@v2
|
32
|
+
with:
|
33
|
+
node-version: '14'
|
34
|
+
- name: Install yarn dep
|
35
|
+
run: yarn install
|
36
|
+
- name: Check prettier
|
37
|
+
run: yarn prettier -c '**/*.rb'
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Verify version change
|
2
|
+
|
3
|
+
on:
|
4
|
+
pull_request:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
version_change:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Fetch main branch
|
15
|
+
run: git fetch origin main:main
|
16
|
+
- name: Verify if there's a change in version
|
17
|
+
run: "git diff main -- lib/dev_oops/version.rb | grep VERSION"
|
18
|
+
- name: Print new version
|
19
|
+
run: 'git diff main -- lib/dev_oops/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?"'
|
20
|
+
- name: Verify if higher version
|
21
|
+
run: '[[ $(git diff main -- lib/dev_oops/version.rb | grep -E "^\+.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") > $(git diff main -- lib/dev_oops/version.rb | grep -E "^-.*VERSION" | grep -E -o "[0-9]+\.[0-9]+\.[0-9]+(\.[0-9]+)?") ]]'
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.0
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [0.2.0] - 2021-04-03
|
11
|
+
|
12
|
+
Refactoring architecture + Basic Documentation
|
13
|
+
|
14
|
+
### Added
|
15
|
+
|
16
|
+
- Documentation
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
|
20
|
+
- Overall gem architecture
|
21
|
+
|
22
|
+
## [0.1.1] - 2021-04-02
|
23
|
+
|
24
|
+
First working version
|
25
|
+
|
26
|
+
### Added
|
27
|
+
|
28
|
+
- All the things
|
29
|
+
|
30
|
+
[unreleased]: https://github.com/zaratan/dev_oops/compare/v0.2.0...HEAD
|
31
|
+
[0.2.0]: https://github.com/zaratan/rspec_in_context/releases/tag/v0.2.0
|
32
|
+
[0.1.1]: https://github.com/zaratan/rspec_in_context/releases/tag/v0.1.1
|
data/README.md
CHANGED
@@ -1,28 +1,109 @@
|
|
1
1
|
# DevOops
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
TODO: Delete this and the text above, and describe your gem
|
3
|
+
This is a gem to help you manage all the scripts and repetitive commands you have written and scatered over the years
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
|
7
|
+
$ gem install dev_oops && dev_oops install
|
8
|
+
|
9
|
+
## Usage
|
10
10
|
|
11
|
-
|
12
|
-
|
11
|
+
This gem will install a new command named `dev_oops`. You can use it from anywhere.
|
12
|
+
|
13
|
+
### TL;DR example
|
14
|
+
|
15
|
+
Config (`dev_oops edit hello`):
|
16
|
+
|
17
|
+
```json
|
18
|
+
{
|
19
|
+
"desc": "Say hello.",
|
20
|
+
"usage": "[--firstname name]",
|
21
|
+
"args": [
|
22
|
+
{
|
23
|
+
"name": "firstname",
|
24
|
+
"desc": "Firstname of the person",
|
25
|
+
"aliases": ["f"],
|
26
|
+
"required": false,
|
27
|
+
"default": "Pierre"
|
28
|
+
}
|
29
|
+
]
|
30
|
+
}
|
13
31
|
```
|
14
32
|
|
15
|
-
|
33
|
+
Script (`dev_oops edit_sh hello`):
|
16
34
|
|
17
|
-
|
35
|
+
```sh
|
36
|
+
echo "Hello $firstname !"
|
37
|
+
```
|
18
38
|
|
19
|
-
|
39
|
+
Shell:
|
40
|
+
|
41
|
+
```sh
|
42
|
+
dev_oops hello --firstname Emy # => Hello Emy !
|
43
|
+
dev_oops hello -f Chris # => Hello Chris !
|
44
|
+
dev_oops hello # => Hello Pierre !
|
45
|
+
dev_oops help hello # =>
|
46
|
+
# Usage:
|
47
|
+
# hello [--firstname name]
|
48
|
+
#
|
49
|
+
# Options:
|
50
|
+
# f, [--firstname=FIRSTNAME] # Firstname of the person
|
51
|
+
# # Default: Pierre
|
52
|
+
```
|
20
53
|
|
21
|
-
|
54
|
+
### Commands
|
22
55
|
|
23
|
-
|
56
|
+
Which editor will be opened by the gem
|
57
|
+
|
58
|
+
#### install
|
59
|
+
|
60
|
+
`dev_oops install` Will create the base directory needed for storing your scripts.
|
61
|
+
|
62
|
+
#### edit
|
63
|
+
|
64
|
+
`dev_oops edit name_of_script` Will open in `$EDITOR` your script [configuration](#config-format).
|
65
|
+
|
66
|
+
#### edit_sh
|
67
|
+
|
68
|
+
`dev_oops edit_sh name_of_script` Will open in `$EDITOR` your script body. Note that the script will be run in `$SHELL`
|
24
69
|
|
25
|
-
|
70
|
+
#### rm
|
71
|
+
|
72
|
+
`dev_oops rm name_of_script` Will remove the config file and the body file from your disk.
|
73
|
+
|
74
|
+
#### help
|
75
|
+
|
76
|
+
`dev_oops help [COMMAND]` Will show help.
|
77
|
+
|
78
|
+
#### [your command]
|
79
|
+
|
80
|
+
`dev_oops [your_command]` Will launch the command.
|
81
|
+
|
82
|
+
### Config format
|
83
|
+
|
84
|
+
Most of the fields are optionals. I would advise filling "desc" and "usage".
|
85
|
+
|
86
|
+
```json
|
87
|
+
{
|
88
|
+
"desc": "A description for what the command do. Will be shown in help.",
|
89
|
+
"usage": "A short usage description. This will be shown in help. The name of the command will be automatically present at the beggining of the usage",
|
90
|
+
"args": [
|
91
|
+
{
|
92
|
+
"name": "name_of_the_arg",
|
93
|
+
"desc": "Description of what the arg does. Will be shown in help.",
|
94
|
+
"aliases": ["a"],
|
95
|
+
"required": false,
|
96
|
+
"default": "aaaaa"
|
97
|
+
},
|
98
|
+
…
|
99
|
+
]
|
100
|
+
}
|
101
|
+
```
|
102
|
+
|
103
|
+
#### Arg format
|
104
|
+
|
105
|
+
The `name` will be used to pass the value in the script as an env variable.
|
106
|
+
You can then access the value with `$name` in the shell script.
|
26
107
|
|
27
108
|
## Development
|
28
109
|
|
@@ -34,7 +115,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
34
115
|
|
35
116
|
Bug reports and pull requests are welcome on GitHub at https://github.com/zaratan/dev_oops. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/zaratan/dev_oops/blob/master/CODE_OF_CONDUCT.md).
|
36
117
|
|
37
|
-
|
38
118
|
## License
|
39
119
|
|
40
120
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
CHANGED
data/bin/local_do
ADDED
data/dev_oops.gemspec
CHANGED
@@ -3,36 +3,48 @@
|
|
3
3
|
require_relative 'lib/dev_oops/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
10
|
-
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
|
14
|
-
spec.
|
6
|
+
spec.name = 'dev_oops'
|
7
|
+
spec.version = DevOops::VERSION
|
8
|
+
spec.authors = ['Denis <Zaratan> Pasin']
|
9
|
+
spec.email = ['zaratan@hey.com']
|
10
|
+
|
11
|
+
spec.summary = 'Shell snipets manager'
|
12
|
+
spec.description =
|
13
|
+
'Shell snipets manager for those scripts you end up copy pasting over and over'
|
14
|
+
spec.homepage = 'https://zaratan.fr'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
|
16
17
|
|
17
18
|
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
+
|
18
20
|
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
19
21
|
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files =
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
spec.files =
|
26
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
27
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
28
|
+
f.match(%r{^(test|spec|features)/})
|
29
|
+
end
|
30
|
+
end
|
31
|
+
spec.bindir = 'exe'
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
33
|
spec.require_paths = ['lib']
|
29
34
|
|
30
35
|
spec.add_runtime_dependency 'thor'
|
36
|
+
spec.add_runtime_dependency 'zeitwerk'
|
31
37
|
|
38
|
+
spec.add_development_dependency 'bundler'
|
39
|
+
spec.add_development_dependency 'bundler-audit', '> 0.6.0'
|
32
40
|
spec.add_development_dependency 'prettier'
|
41
|
+
spec.add_development_dependency 'pry-byebug'
|
42
|
+
spec.add_development_dependency 'rake'
|
43
|
+
spec.add_development_dependency 'rspec'
|
33
44
|
spec.add_development_dependency 'rubocop'
|
34
45
|
spec.add_development_dependency 'rubocop-performance'
|
35
46
|
spec.add_development_dependency 'solargraph'
|
36
47
|
|
37
|
-
spec.post_install_message =
|
48
|
+
spec.post_install_message =
|
49
|
+
'Run `dev_oops install` to create the base directory for dev_oops'
|
38
50
|
end
|
data/lib/dev_oops.rb
CHANGED
@@ -6,165 +6,16 @@ require 'fileutils'
|
|
6
6
|
require 'json'
|
7
7
|
require 'thor'
|
8
8
|
|
9
|
+
require 'zeitwerk'
|
10
|
+
loader = Zeitwerk::Loader.for_gem
|
11
|
+
loader.setup # ready!
|
12
|
+
|
9
13
|
module DevOops
|
10
14
|
class Error < StandardError
|
11
15
|
end
|
12
16
|
|
13
|
-
#
|
14
|
-
|
17
|
+
# TODO Refactor
|
15
18
|
CONFIG_DIR = "#{ENV['HOME']}/.dev_oops"
|
16
|
-
|
17
|
-
module ConfigLoader
|
18
|
-
def self.load
|
19
|
-
Dir
|
20
|
-
.glob("#{CONFIG_DIR}/*.json")
|
21
|
-
.map do |filename|
|
22
|
-
script_location = filename.gsub(/\.json$/, '.sh')
|
23
|
-
script_location = '' unless File.exist?(script_location)
|
24
|
-
json_config = nil
|
25
|
-
File.open(filename) { |file| json_config = JSON.parse(file.read) }
|
26
|
-
script_name =
|
27
|
-
%r{(?<script_name>[^/]+).json$}.match(filename)['script_name']
|
28
|
-
|
29
|
-
OpenStruct.new(
|
30
|
-
{
|
31
|
-
name: script_name,
|
32
|
-
desc: json_config['desc'],
|
33
|
-
usage: "#{script_name} #{json_config['usage'] || ''}",
|
34
|
-
command: json_config['command'],
|
35
|
-
script_location:
|
36
|
-
json_config['script_location'] || script_location,
|
37
|
-
args: json_config['args'],
|
38
|
-
},
|
39
|
-
)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class EditScript < Thor::Group
|
45
|
-
include Thor::Actions
|
46
|
-
|
47
|
-
def self.source_root
|
48
|
-
"#{File.dirname(__FILE__)}/.."
|
49
|
-
end
|
50
|
-
|
51
|
-
argument :script_name
|
52
|
-
def edit
|
53
|
-
path = "#{CONFIG_DIR}/#{script_name}.json"
|
54
|
-
template 'templates/empty_script.tt', path unless File.exist?(path)
|
55
|
-
system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.json")
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
class EditScriptSh < Thor::Group
|
60
|
-
include Thor::Actions
|
61
|
-
|
62
|
-
def self.source_root
|
63
|
-
"#{File.dirname(__FILE__)}/.."
|
64
|
-
end
|
65
|
-
|
66
|
-
argument :script_name
|
67
|
-
def edit
|
68
|
-
path = "#{CONFIG_DIR}/#{script_name}.sh"
|
69
|
-
FileUtils.touch(path) unless File.exist?(path)
|
70
|
-
FileUtils.chmod(0o750, path)
|
71
|
-
system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.sh")
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
class RemoveScript < Thor::Group
|
76
|
-
argument :script_name, desc: 'name of the script'
|
77
|
-
|
78
|
-
def remove_sh
|
79
|
-
return unless File.exist?("#{CONFIG_DIR}/#{script_name}.sh")
|
80
|
-
FileUtils.remove "#{CONFIG_DIR}/#{script_name}.sh"
|
81
|
-
end
|
82
|
-
|
83
|
-
def remove_json
|
84
|
-
return unless File.exist?("#{CONFIG_DIR}/#{script_name}.json")
|
85
|
-
FileUtils.remove "#{CONFIG_DIR}/#{script_name}.json"
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
class Runner < Thor
|
90
|
-
include Thor::Actions
|
91
|
-
REGISTERED_CLASS_METHODS = {} # rubocop:disable Style/MutableConstant
|
92
|
-
|
93
|
-
def self.source_root
|
94
|
-
"#{File.dirname(__FILE__)}/.."
|
95
|
-
end
|
96
|
-
|
97
|
-
def self.register(klass, subcommand_name, usage, description, options = {})
|
98
|
-
REGISTERED_CLASS_METHODS[subcommand_name] = klass if klass <= Thor::Group
|
99
|
-
super
|
100
|
-
end
|
101
|
-
|
102
|
-
configs = ConfigLoader.load
|
103
|
-
configs.each do |config|
|
104
|
-
new_action =
|
105
|
-
Class.new(Thor::Group) do
|
106
|
-
# (config.args || []).each { |arg| argument arg }
|
107
|
-
(config.args || []).each do |arg|
|
108
|
-
if arg.is_a? String
|
109
|
-
class_option arg
|
110
|
-
else
|
111
|
-
class_option arg['name'],
|
112
|
-
desc: arg['desc'] || '',
|
113
|
-
aliases: arg['aliases'] || [],
|
114
|
-
required: arg['required'] || false,
|
115
|
-
default: arg['default']
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
define_singleton_method('banner') { config.usage }
|
120
|
-
|
121
|
-
define_method('perform') do
|
122
|
-
env_vars = options.map { |k, v| "#{k}=#{v}" }.join(' ')
|
123
|
-
|
124
|
-
if config.command && !config.command.empty?
|
125
|
-
system("#{env_vars} #{config.command}")
|
126
|
-
end
|
127
|
-
if config.script_location && !config.script_location.empty?
|
128
|
-
location =
|
129
|
-
if config.script_location.start_with?('/')
|
130
|
-
config.script_location
|
131
|
-
else
|
132
|
-
"#{ENV['HOME']}/#{config.script_location}"
|
133
|
-
end
|
134
|
-
system("#{env_vars} zsh -c #{location}")
|
135
|
-
end
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
register(new_action, config.name, config.usage, config.desc)
|
140
|
-
end
|
141
|
-
|
142
|
-
register(EditScript, 'edit', 'edit SCRIPT_NAME', 'Edit a script config')
|
143
|
-
register(
|
144
|
-
EditScriptSh,
|
145
|
-
'edit_sh',
|
146
|
-
'edit_sh SCRIPT_NAME',
|
147
|
-
'Edit the script bash',
|
148
|
-
)
|
149
|
-
register(RemoveScript, 'rm', 'rm SCRIPT_NAME', 'Remove a script')
|
150
|
-
|
151
|
-
# contents of the Thor class
|
152
|
-
desc 'install', 'Create the neccesary directory for the gem'
|
153
|
-
def install
|
154
|
-
return if Dir.exist?(CONFIG_DIR)
|
155
|
-
|
156
|
-
FileUtils.mkdir CONFIG_DIR
|
157
|
-
end
|
158
|
-
|
159
|
-
def help(subcommand = nil)
|
160
|
-
if subcommand && respond_to?(subcommand)
|
161
|
-
klass = REGISTERED_CLASS_METHODS[subcommand]
|
162
|
-
klass.start(['-h'])
|
163
|
-
else
|
164
|
-
super
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
private
|
169
|
-
end
|
170
19
|
end
|
20
|
+
|
21
|
+
loader.eager_load
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DevOops
|
3
|
+
module Commands
|
4
|
+
class EditScript < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
"#{File.dirname(__FILE__)}/../../../"
|
9
|
+
end
|
10
|
+
|
11
|
+
argument :script_name
|
12
|
+
def edit
|
13
|
+
path = "#{CONFIG_DIR}/#{script_name}.json"
|
14
|
+
template 'templates/empty_script.tt', path unless File.exist?(path)
|
15
|
+
system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.json")
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DevOops
|
3
|
+
module Commands
|
4
|
+
class EditScriptSh < Thor::Group
|
5
|
+
include Thor::Actions
|
6
|
+
|
7
|
+
argument :script_name
|
8
|
+
def edit
|
9
|
+
path = "#{CONFIG_DIR}/#{script_name}.sh"
|
10
|
+
FileUtils.touch(path) unless File.exist?(path)
|
11
|
+
FileUtils.chmod(0o750, path)
|
12
|
+
system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.sh")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DevOops
|
3
|
+
module Commands
|
4
|
+
class RemoveScript < Thor::Group
|
5
|
+
argument :script_name, desc: 'name of the script'
|
6
|
+
|
7
|
+
def remove_sh
|
8
|
+
return unless File.exist?("#{CONFIG_DIR}/#{script_name}.sh")
|
9
|
+
FileUtils.remove "#{CONFIG_DIR}/#{script_name}.sh"
|
10
|
+
end
|
11
|
+
|
12
|
+
def remove_json
|
13
|
+
return unless File.exist?("#{CONFIG_DIR}/#{script_name}.json")
|
14
|
+
FileUtils.remove "#{CONFIG_DIR}/#{script_name}.json"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DevOops
|
3
|
+
class Runner < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
REGISTERED_CLASS_METHODS = {} # rubocop:disable Style/MutableConstant
|
6
|
+
|
7
|
+
def self.source_root
|
8
|
+
"#{File.dirname(__FILE__)}/.."
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.register(klass, subcommand_name, usage, description, options = {})
|
12
|
+
REGISTERED_CLASS_METHODS[subcommand_name] = klass if klass <= Thor::Group
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
configs = ScriptsLoader.load
|
17
|
+
configs.each do |config|
|
18
|
+
next if ScriptsLoader::FORBIDDEN_NAMES.include?(config.name)
|
19
|
+
|
20
|
+
new_action = ScriptsLoader.build_action(config)
|
21
|
+
|
22
|
+
register(new_action, config.name, config.usage, config.desc)
|
23
|
+
end
|
24
|
+
|
25
|
+
register(
|
26
|
+
Commands::EditScript,
|
27
|
+
'edit',
|
28
|
+
'edit SCRIPT_NAME',
|
29
|
+
'Edit a script config'
|
30
|
+
)
|
31
|
+
register(
|
32
|
+
Commands::EditScriptSh,
|
33
|
+
'edit_sh',
|
34
|
+
'edit_sh SCRIPT_NAME',
|
35
|
+
'Edit the script bash'
|
36
|
+
)
|
37
|
+
register(Commands::RemoveScript, 'rm', 'rm SCRIPT_NAME', 'Remove a script')
|
38
|
+
|
39
|
+
# contents of the Thor class
|
40
|
+
desc 'install', 'Create the neccesary directory for the gem'
|
41
|
+
def install
|
42
|
+
return if Dir.exist?(CONFIG_DIR)
|
43
|
+
|
44
|
+
FileUtils.mkdir CONFIG_DIR
|
45
|
+
end
|
46
|
+
|
47
|
+
def help(subcommand = nil)
|
48
|
+
if subcommand && respond_to?(subcommand)
|
49
|
+
klass = REGISTERED_CLASS_METHODS[subcommand]
|
50
|
+
klass.start(['-h'])
|
51
|
+
else
|
52
|
+
super
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module DevOops
|
3
|
+
module ScriptsLoader
|
4
|
+
FORBIDDEN_NAMES = %w[help install edit edit_sh rm].freeze
|
5
|
+
ScriptConfig =
|
6
|
+
Struct.new(:name, :desc, :usage, :script_location, :args) do
|
7
|
+
def self.create(script_name, script_location, json_config)
|
8
|
+
new(
|
9
|
+
script_name,
|
10
|
+
json_config['desc'] || 'Missing description',
|
11
|
+
"#{script_name} #{json_config['usage'] || ''}",
|
12
|
+
script_location,
|
13
|
+
json_config['args']
|
14
|
+
)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.load
|
19
|
+
Dir
|
20
|
+
.glob("#{CONFIG_DIR}/*.json")
|
21
|
+
.map do |filename|
|
22
|
+
script_location = filename.gsub(/\.json$/, '.sh')
|
23
|
+
script_location = '' unless File.exist?(script_location)
|
24
|
+
json_config = nil
|
25
|
+
File.open(filename) { |file| json_config = JSON.parse(file.read) }
|
26
|
+
script_name =
|
27
|
+
%r{(?<script_name>[^/]+).json$}.match(filename)['script_name']
|
28
|
+
|
29
|
+
ScriptConfig.create(script_name, script_location, json_config)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.build_action(config)
|
34
|
+
Class.new(Thor::Group) do
|
35
|
+
(config.args || []).each do |arg|
|
36
|
+
class_option(
|
37
|
+
arg['name'],
|
38
|
+
desc: arg['desc'] || '',
|
39
|
+
aliases: arg['aliases'] || [],
|
40
|
+
required: arg['required'] || false,
|
41
|
+
default: arg['default']
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
define_singleton_method('banner') { config.usage }
|
46
|
+
|
47
|
+
define_method('perform') do
|
48
|
+
env_vars = options.map { |k, v| "#{k}=#{v}" }.join(' ')
|
49
|
+
|
50
|
+
if config.script_location && !config.script_location.empty?
|
51
|
+
location =
|
52
|
+
if config.script_location.start_with?('/')
|
53
|
+
config.script_location
|
54
|
+
else
|
55
|
+
"#{ENV['HOME']}/#{config.script_location}"
|
56
|
+
end
|
57
|
+
system("#{env_vars} #{ENV['SHELL']} -c #{location}")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/lib/dev_oops/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_oops
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis <Zaratan> Pasin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -24,6 +24,48 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: zeitwerk
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler-audit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.6.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.6.0
|
27
69
|
- !ruby/object:Gem::Dependency
|
28
70
|
name: prettier
|
29
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,6 +80,48 @@ dependencies:
|
|
38
80
|
- - ">="
|
39
81
|
- !ruby/object:Gem::Version
|
40
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
41
125
|
- !ruby/object:Gem::Dependency
|
42
126
|
name: rubocop
|
43
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,21 +173,31 @@ executables:
|
|
89
173
|
extensions: []
|
90
174
|
extra_rdoc_files: []
|
91
175
|
files:
|
176
|
+
- ".github/workflows/test_and_publish.yml"
|
177
|
+
- ".github/workflows/test_only.yml"
|
178
|
+
- ".github/workflows/verify_version_change.yml"
|
92
179
|
- ".gitignore"
|
93
180
|
- ".rspec"
|
94
181
|
- ".rubocop-http---relaxed-ruby-style-rubocop-yml"
|
95
182
|
- ".rubocop.yml"
|
96
|
-
- ".
|
183
|
+
- ".ruby-version"
|
184
|
+
- CHANGELOG.md
|
97
185
|
- CODE_OF_CONDUCT.md
|
98
186
|
- Gemfile
|
99
187
|
- LICENSE.txt
|
100
188
|
- README.md
|
101
189
|
- Rakefile
|
102
190
|
- bin/console
|
191
|
+
- bin/local_do
|
103
192
|
- bin/setup
|
104
193
|
- dev_oops.gemspec
|
105
194
|
- exe/dev_oops
|
106
195
|
- lib/dev_oops.rb
|
196
|
+
- lib/dev_oops/commands/edit_script.rb
|
197
|
+
- lib/dev_oops/commands/edit_script_sh.rb
|
198
|
+
- lib/dev_oops/commands/remove_script.rb
|
199
|
+
- lib/dev_oops/runner.rb
|
200
|
+
- lib/dev_oops/scripts_loader.rb
|
107
201
|
- lib/dev_oops/version.rb
|
108
202
|
- package.json
|
109
203
|
- templates/empty_script.tt
|
@@ -128,8 +222,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
222
|
- !ruby/object:Gem::Version
|
129
223
|
version: '0'
|
130
224
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
225
|
+
rubygems_version: 3.2.3
|
226
|
+
signing_key:
|
133
227
|
specification_version: 4
|
134
228
|
summary: Shell snipets manager
|
135
229
|
test_files: []
|