dev_oops 0.2.0.1 → 0.3.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: 32ee75a41461d7793d454367ce09a989c796df9a50c861d27795a5864e74a9ca
4
- data.tar.gz: 0351c14d9116a45119a773c69fd1dc493837a48b06366d3b4a2977c34428673a
3
+ metadata.gz: c0756192a829fa282dfacaa2be870bd6c97102ce76b197e4afb7ed55a290d805
4
+ data.tar.gz: '058272644fb82265682974985c453e1976e0788de6e82c7192170eeeb5450390'
5
5
  SHA512:
6
- metadata.gz: 989bb33a56ad674bdfc1a47719648b5111668af45d160c2e971113ca56ccc7dc27c8862962b7c9cae20700f3c2b6e5ff3853239f6a621c96afe066c2871ddc70
7
- data.tar.gz: 4f967de470975239f896074dea2bf86869647dd3d0f3820f503a0e195539446f99b3e0cdcbc5b5143a884889e4944e20d8d94a07c51a39db1c45a5a14affe1eb
6
+ metadata.gz: 1a501ce812965c99a54024bce23b7bd7e61b01679644085289f665b9339cf59c8c3c50e0c15c752a24af409cbd82c8107a5f38b20509e26f6afa6caedac2ee16
7
+ data.tar.gz: 222ecba063dac5454fa32592b2cef2224c266cbe96473f69c064e73599f31e5e34e2907c2132609ea26d63b0c923cb58f88bc1424747159b66f8917f0403f1f2
data/README.md CHANGED
@@ -4,7 +4,21 @@ This is a gem to help you manage all the scripts and repetitive commands you hav
4
4
 
5
5
  ## Installation
6
6
 
7
- $ gem install dev_oops && dev_oops install
7
+ There's 2 main ways to install and use this gem.
8
+
9
+ ### Global install
10
+
11
+ $ gem install dev_oops
12
+
13
+ ### Bundler way
14
+
15
+ Add this gem to your Gemfile
16
+
17
+ ```
18
+ gem 'dev_oops'
19
+ ```
20
+
21
+ Then `bundle install`
8
22
 
9
23
  ## Usage
10
24
 
@@ -51,13 +65,31 @@ dev_oops help hello # =>
51
65
  # # Default: Pierre
52
66
  ```
53
67
 
54
- ### Commands
68
+ ### Script locations
69
+
70
+ By default this gem will use the `$HOME/.dev_oops` directory to install configs and scripts.
55
71
 
56
- Which editor will be opened by the gem
72
+ This gem will also try to find every `dev_oops` directory between the current directory and home and look for scripts in them.
57
73
 
58
- #### install
74
+ If there's a name collision, the closest to `current_dir` will be chosen.
59
75
 
60
- `dev_oops install` Will create the base directory needed for storing your scripts.
76
+ This search will also be done while editing or removing a script. It will use:
77
+
78
+ 1. The existing script with the same name
79
+ 2. Or, the `./dev_oops` directory if exists
80
+ 3. Or, the `$HOME/.dev_oops` directory otherwise
81
+
82
+ All `edit`, `edit_sh` and `rm` commands (see lower) have a `--global` or `-g` option to bypass the search and use the `$HOME/.dev_oops` directory.
83
+
84
+ #### Creating a local directory
85
+
86
+ `bundle exec dev_oops local_install`.
87
+
88
+ This will create a `./dev_oops` directory.
89
+
90
+ ### Commands
91
+
92
+ Which editor will be opened by the gem is dictated by the `$EDITOR` environment variable.
61
93
 
62
94
  #### edit
63
95
 
@@ -111,6 +143,8 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
111
143
 
112
144
  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).
113
145
 
146
+ Be carefull, in dev your directory will be detected as a local directory (because of its name). Do not remove the "package" script.
147
+
114
148
  ## Contributing
115
149
 
116
150
  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).
data/lib/dev_oops.rb CHANGED
@@ -13,9 +13,6 @@ loader.setup # ready!
13
13
  module DevOops
14
14
  class Error < StandardError
15
15
  end
16
-
17
- # TODO Refactor
18
- CONFIG_DIR = "#{ENV['HOME']}/.dev_oops"
19
16
  end
20
17
 
21
18
  loader.eager_load
@@ -9,10 +9,25 @@ module DevOops
9
9
  end
10
10
 
11
11
  argument :script_name
12
+ class_option :global,
13
+ desc: 'force the script to be global',
14
+ aliases: ['g'],
15
+ type: :boolean
16
+
17
+ def self.banner
18
+ "#{$PROGRAM_NAME} edit SCRIPT_NAME"
19
+ end
20
+
12
21
  def edit
13
- path = "#{CONFIG_DIR}/#{script_name}.json"
22
+ script_dir =
23
+ if options[:global]
24
+ ScriptsLoader::GLOBAL_DIR
25
+ else
26
+ ScriptsLoader.script_dir(script_name)
27
+ end
28
+ path = "#{script_dir}/#{script_name}.json"
14
29
  template 'templates/empty_script.tt', path unless File.exist?(path)
15
- system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.json")
30
+ system("#{ENV['EDITOR'] || 'vim'} #{path}")
16
31
  end
17
32
  end
18
33
  end
@@ -4,12 +4,31 @@ module DevOops
4
4
  class EditScriptSh < Thor::Group
5
5
  include Thor::Actions
6
6
 
7
+ def self.source_root
8
+ "#{File.dirname(__FILE__)}/../../../"
9
+ end
10
+
7
11
  argument :script_name
12
+ class_option :global,
13
+ desc: 'force the script to be global',
14
+ aliases: ['g'],
15
+ type: :boolean
16
+
17
+ def self.banner
18
+ "#{$PROGRAM_NAME} edit_sh SCRIPT_NAME"
19
+ end
20
+
8
21
  def edit
9
- path = "#{CONFIG_DIR}/#{script_name}.sh"
10
- FileUtils.touch(path) unless File.exist?(path)
22
+ script_dir =
23
+ if options[:global]
24
+ ScriptsLoader::GLOBAL_DIR
25
+ else
26
+ ScriptsLoader.script_dir(script_name)
27
+ end
28
+ path = "#{script_dir}/#{script_name}.sh"
29
+ create_file(path) unless File.exist?(path)
11
30
  FileUtils.chmod(0o750, path)
12
- system("#{ENV['EDITOR'] || 'vim'} #{CONFIG_DIR}/#{script_name}.sh")
31
+ system("#{ENV['EDITOR'] || 'vim'} #{path}")
13
32
  end
14
33
  end
15
34
  end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ module DevOops
3
+ module Commands
4
+ class LocalInstall < Thor::Group
5
+ def install
6
+ return if Dir.exist?('./dev_oops')
7
+
8
+ FileUtils.mkdir './dev_oops'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,16 +2,33 @@
2
2
  module DevOops
3
3
  module Commands
4
4
  class RemoveScript < Thor::Group
5
+ include Thor::Actions
6
+
7
+ def self.source_root
8
+ "#{File.dirname(__FILE__)}/../../../"
9
+ end
10
+
5
11
  argument :script_name, desc: 'name of the script'
12
+ class_option :global,
13
+ desc: 'force the script to be global',
14
+ aliases: ['g'],
15
+ type: :boolean
6
16
 
7
- def remove_sh
8
- return unless File.exist?("#{CONFIG_DIR}/#{script_name}.sh")
9
- FileUtils.remove "#{CONFIG_DIR}/#{script_name}.sh"
17
+ def self.banner
18
+ "#{$PROGRAM_NAME} rm SCRIPT_NAME"
10
19
  end
11
20
 
12
21
  def remove_json
13
- return unless File.exist?("#{CONFIG_DIR}/#{script_name}.json")
14
- FileUtils.remove "#{CONFIG_DIR}/#{script_name}.json"
22
+ script_dir =
23
+ if options[:global]
24
+ ScriptsLoader::GLOBAL_DIR
25
+ else
26
+ ScriptsLoader.script_dir(script_name)
27
+ end
28
+ json_path = "#{script_dir}/#{script_name}.json"
29
+ sh_path = "#{script_dir}/#{script_name}.sh"
30
+ remove_file json_path if File.exist?(json_path)
31
+ remove_file sh_path if File.exist?(sh_path)
15
32
  end
16
33
  end
17
34
  end
@@ -4,6 +4,9 @@ module DevOops
4
4
  include Thor::Actions
5
5
  REGISTERED_CLASS_METHODS = {} # rubocop:disable Style/MutableConstant
6
6
 
7
+ CONFIG_DIR = "#{ENV['HOME']}/.dev_oops"
8
+ FileUtils.mkdir CONFIG_DIR unless Dir.exist?(CONFIG_DIR)
9
+
7
10
  def self.source_root
8
11
  "#{File.dirname(__FILE__)}/.."
9
12
  end
@@ -28,21 +31,22 @@ module DevOops
28
31
  'edit SCRIPT_NAME',
29
32
  'Edit a script config'
30
33
  )
34
+
31
35
  register(
32
36
  Commands::EditScriptSh,
33
37
  'edit_sh',
34
38
  'edit_sh SCRIPT_NAME',
35
39
  'Edit the script bash'
36
40
  )
37
- register(Commands::RemoveScript, 'rm', 'rm SCRIPT_NAME', 'Remove a script')
38
41
 
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)
42
+ register(Commands::RemoveScript, 'rm', 'rm SCRIPT_NAME', 'Remove a script')
43
43
 
44
- FileUtils.mkdir CONFIG_DIR
45
- end
44
+ register(
45
+ Commands::LocalInstall,
46
+ 'install',
47
+ 'install',
48
+ 'Create the neccesary local directory for the gem'
49
+ )
46
50
 
47
51
  def help(subcommand = nil)
48
52
  if subcommand && respond_to?(subcommand)
@@ -1,33 +1,62 @@
1
1
  # frozen_string_literal: true
2
2
  module DevOops
3
3
  module ScriptsLoader
4
- FORBIDDEN_NAMES = %w[help install edit edit_sh rm].freeze
4
+ FORBIDDEN_NAMES = %w[help install edit edit_sh rm local_install].freeze
5
+ GLOBAL_DIR = "#{Dir.home}/.dev_oops"
5
6
  ScriptConfig =
6
- Struct.new(:name, :desc, :usage, :script_location, :args) do
7
- def self.create(script_name, script_location, json_config)
7
+ Struct.new(:name, :desc, :usage, :script_location, :args, :dir) do
8
+ def self.create(script_name, script_location, json_config, dir)
8
9
  new(
9
10
  script_name,
10
11
  json_config['desc'] || 'Missing description',
11
12
  "#{script_name} #{json_config['usage'] || ''}",
12
13
  script_location,
13
- json_config['args']
14
+ json_config['args'],
15
+ dir
14
16
  )
15
17
  end
16
18
  end
17
19
 
20
+ def self.find_dev_oops_dirs
21
+ [
22
+ GLOBAL_DIR,
23
+ *Dir.pwd.gsub("#{Dir.home}/", '').split('/').reduce(
24
+ []
25
+ ) { |res, new_dir| [*res, "#{res.last}/#{new_dir}"] }.map do |dir|
26
+ "#{Dir.home}#{dir}/dev_oops"
27
+ end.select { |dir| Dir.exist?(dir) }
28
+ ]
29
+ end
30
+
18
31
  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)
32
+ find_dev_oops_dirs.flat_map do |dir|
33
+ Dir.glob("#{dir}/*.json")
34
+ end.map do |filename|
35
+ script_location = filename.gsub(/\.json$/, '.sh')
36
+ script_location = '' unless File.exist?(script_location)
37
+ json_config = nil
38
+ File.open(filename) { |file| json_config = JSON.parse(file.read) }
39
+ script_name = File.basename(filename, '.json')
40
+
41
+ ScriptConfig.create(
42
+ script_name,
43
+ script_location,
44
+ json_config,
45
+ File.dirname(filename)
46
+ )
47
+ end.reverse.reduce([]) do |res, script_config|
48
+ if res.any? { |script_c| script_c.name == script_config.name }
49
+ res
50
+ else
51
+ [*res, script_config]
30
52
  end
53
+ end
54
+ end
55
+
56
+ def self.script_dir(script_name)
57
+ scripts = self.load
58
+ scripts.find { |script| script.name == script_name }&.dir ||
59
+ Dir.exist?("#{Dir.pwd}/dev_oops") && "#{Dir.pwd}/dev_oops" || GLOBAL_DIR
31
60
  end
32
61
 
33
62
  def self.build_action(config)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DevOops
4
- VERSION = '0.2.0.1'
4
+ VERSION = '0.3.0'
5
5
  end
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.2.0.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis <Zaratan> Pasin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-03 00:00:00.000000000 Z
11
+ date: 2021-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -195,6 +195,7 @@ files:
195
195
  - lib/dev_oops.rb
196
196
  - lib/dev_oops/commands/edit_script.rb
197
197
  - lib/dev_oops/commands/edit_script_sh.rb
198
+ - lib/dev_oops/commands/local_install.rb
198
199
  - lib/dev_oops/commands/remove_script.rb
199
200
  - lib/dev_oops/runner.rb
200
201
  - lib/dev_oops/scripts_loader.rb