al-commands 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc4b9970dfa91ffe3f4ee503c095e4efba6cf23e2be5d5fad352a22d315618b4
4
+ data.tar.gz: 871a81bde72d27e345124fd98ad867f4db57cdd8dad77431918426fc759810d7
5
+ SHA512:
6
+ metadata.gz: 89cc82c5a9d7c52d30262a9d50088f1f5a433546851aaacc05e7fa026627fd6d9c781a1b2b031077c19111a62aba72afef1064d7ffaa89c481020eef1c1623a8
7
+ data.tar.gz: 4f61dae14e1b50efb18b32a5ed4148a200100ec0334e218288b627f1796a54ebe6bb96dca328c1b8351ba244bc8caa26088f70a0914b6c61dde5bd762b04d14b
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.4
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in commands.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem "minitest", "~> 5.0"
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Commands
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/commands`. 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 'commands'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install commands
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 test` 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]/commands.
36
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "commands"
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 ADDED
@@ -0,0 +1,8 @@
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
data/commands.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ require_relative 'lib/commands/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = "al-commands"
5
+ spec.version = Commands::VERSION
6
+ spec.authors = ["Arnaud Lécuyer"]
7
+ spec.email = ["alsquire@gmail.com"]
8
+
9
+ spec.summary = %q{Display a menu from ./commands.yml with commands executable}
10
+ spec.description = %q{Display a menu from ./commands.yml with commands executable}
11
+ spec.homepage = "https://github.com/AlSquire/commands"
12
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
13
+
14
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "https://github.com/AlSquire/commands/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+ end
data/exe/commands ADDED
@@ -0,0 +1,87 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Put this file in your PATH and give it execution rights, run to have a commands.yml example.
4
+ # Alias it and/or remove .rb extension for convenience.
5
+ # Usage:
6
+ # commands.rb [ALIAS_OR_NUMBER [ARGS]]
7
+
8
+ # TODO: stdin and stdout for shell compatibility (useful?)
9
+ require 'readline'
10
+ require 'yaml'
11
+
12
+ # Check for commands.yml in current working directory
13
+ file = File.read('commands.yml') rescue nil
14
+
15
+ # If command contains %{argX}, replace it with the Xth argument
16
+ # Otherwise, all arguments are put at the end of command
17
+ def resolve_command_line(command, args)
18
+ if command.match(/%\{arg\d+\}/)
19
+ hashed_args = {}
20
+ args.each.with_index do |arg, index|
21
+ hashed_args["arg#{index + 1}".to_sym] = arg
22
+ end
23
+
24
+ command % hashed_args
25
+ else
26
+ [command, args] * ' '
27
+ end
28
+ end
29
+
30
+ if file
31
+ commands = YAML.load(file)
32
+
33
+ input, *args = ARGV
34
+
35
+ if !input
36
+ # Display commands
37
+ commands.each.with_index do |command, index|
38
+ puts
39
+ puts "#{index + 1}/ #{command['desc']}"
40
+ puts "=> #{command['command']}"
41
+ puts "- alias: #{command['alias']}" if command['alias']
42
+ end
43
+
44
+ puts
45
+ puts "Enter a number or alias followed by optional args, nothing to exit"
46
+ puts
47
+
48
+ prompt = "> "
49
+ input, *args = Readline.readline(prompt, true).split(' ')
50
+ end
51
+
52
+ if input && input != ""
53
+ command = if input.match? /^[1-9][0-9]*$/
54
+ commands[input.to_i - 1]
55
+ else
56
+ commands.detect do |c|
57
+ c['alias'] && c['alias'] == input
58
+ end
59
+ end
60
+
61
+ if command
62
+ command_line = resolve_command_line(command['command'], args)
63
+
64
+ puts " => #{command_line}"
65
+ system(command_line)
66
+ else
67
+ puts "No command found for #{input}"
68
+ end
69
+ end
70
+ else
71
+ puts "commands.yml not found in current directory"
72
+ puts
73
+ puts "Example of commands.yml:"
74
+ puts %Q{
75
+ -
76
+ desc: "Rails server"
77
+ command: "bundle exec rails server"
78
+ alias: "rs"
79
+ -
80
+ desc: "Webpack dev server"
81
+ command: "./bin/webpack-dev-server"
82
+ alias: "ws"
83
+ -
84
+ desc: "Some reversed ordered arguments"
85
+ command: "echo %{arg3} %{arg2} %{arg1}"
86
+ }
87
+ end
@@ -0,0 +1,3 @@
1
+ module Commands
2
+ VERSION = "0.1.0"
3
+ end
data/lib/commands.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "commands/version"
2
+
3
+ module Commands
4
+ class Error < StandardError; end
5
+ # Your code goes here...
6
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: al-commands
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Arnaud Lécuyer
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-09-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Display a menu from ./commands.yml with commands executable
14
+ email:
15
+ - alsquire@gmail.com
16
+ executables:
17
+ - commands
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".gitignore"
22
+ - ".travis.yml"
23
+ - Gemfile
24
+ - README.md
25
+ - Rakefile
26
+ - bin/console
27
+ - bin/setup
28
+ - commands.gemspec
29
+ - exe/commands
30
+ - lib/commands.rb
31
+ - lib/commands/version.rb
32
+ homepage: https://github.com/AlSquire/commands
33
+ licenses: []
34
+ metadata:
35
+ homepage_uri: https://github.com/AlSquire/commands
36
+ source_code_uri: https://github.com/AlSquire/commands
37
+ changelog_uri: https://github.com/AlSquire/commands/CHANGELOG.md
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.3.0
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.1.6
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Display a menu from ./commands.yml with commands executable
57
+ test_files: []