yapo 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +46 -0
- data/README.md +71 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/yapo +19 -0
- data/lib/yapo.rb +10 -0
- data/lib/yapo/cli.rb +35 -0
- data/lib/yapo/command.rb +70 -0
- data/lib/yapo/commands/exec.rb +46 -0
- data/lib/yapo/config/configurations.rb +39 -0
- data/lib/yapo/config/default.example.yml +55 -0
- data/lib/yapo/config/default.yml +59 -0
- data/lib/yapo/helpers/commands.rb +30 -0
- data/lib/yapo/helpers/custom_errors.rb +96 -0
- data/lib/yapo/helpers/teletype.rb +34 -0
- data/lib/yapo/helpers/validations.rb +19 -0
- data/lib/yapo/version.rb +3 -0
- data/yapo.gemspec +31 -0
- metadata +151 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bf5cf5a79f7fc498dce08c4606ed9dc9ea00f68f
|
4
|
+
data.tar.gz: 40854cf38ad7eafa71121dcf6a65f169e1863951
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7a3a5a2168f1bd42f90d05a7201449652b616597da53f8bc4b09d114506d90a9a0004bc26d0530daa79f6e3d70361f838692e72f7c6aaed00d93b8b57af6d9ad
|
7
|
+
data.tar.gz: 05cabb8aef753f52edb426d37ca882fb4b4892ea0a2a3703ee51d9b8470713de9f54a657ac950da72a1129de707a60790722a68ac1fd5f7a272a0860a010a5e3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yapo (0.1.0)
|
5
|
+
pastel (~> 0.7.2)
|
6
|
+
thor (~> 0.19.4)
|
7
|
+
tty-command (~> 0.7.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
diff-lcs (1.3)
|
13
|
+
equatable (0.5.0)
|
14
|
+
pastel (0.7.2)
|
15
|
+
equatable (~> 0.5.0)
|
16
|
+
tty-color (~> 0.4.0)
|
17
|
+
rake (10.5.0)
|
18
|
+
rspec (3.7.0)
|
19
|
+
rspec-core (~> 3.7.0)
|
20
|
+
rspec-expectations (~> 3.7.0)
|
21
|
+
rspec-mocks (~> 3.7.0)
|
22
|
+
rspec-core (3.7.1)
|
23
|
+
rspec-support (~> 3.7.0)
|
24
|
+
rspec-expectations (3.7.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.7.0)
|
27
|
+
rspec-mocks (3.7.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.7.0)
|
30
|
+
rspec-support (3.7.1)
|
31
|
+
thor (0.19.4)
|
32
|
+
tty-color (0.4.2)
|
33
|
+
tty-command (0.7.0)
|
34
|
+
pastel (~> 0.7.0)
|
35
|
+
|
36
|
+
PLATFORMS
|
37
|
+
ruby
|
38
|
+
|
39
|
+
DEPENDENCIES
|
40
|
+
bundler (~> 1.16)
|
41
|
+
rake (~> 10.0)
|
42
|
+
rspec (~> 3.0)
|
43
|
+
yapo!
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
1.16.1
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Yapo
|
2
|
+
|
3
|
+
This gem is used for building powerful command-line interfaces.
|
4
|
+
It can also be used for simplifying the integration and daily usage of any third party CLIs.
|
5
|
+
|
6
|
+
You will be able to run bash scripts in your project by creating your custom, and easy to memorize, commands. That way, you won't need to remember some confusing instructions, or third party commands, to run and contribute to a project that you are working on.
|
7
|
+
|
8
|
+
Using Yapo, you will reduce the setup time in any project that needs a big set of instructions to start up the project.
|
9
|
+
|
10
|
+
Please review the list of [examples](#examples), and feel free to use them.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Run this in your terminal to install the gem globally in your machine:
|
15
|
+
```console
|
16
|
+
$ gem install yapo
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Add a .yapo.yml file in the root of your project, and fill it with whatever command you want to create. File example:
|
22
|
+
```yaml
|
23
|
+
version: '0.1.0'
|
24
|
+
# OPTIONAL
|
25
|
+
build: &build
|
26
|
+
- "echo Building Hello World!"
|
27
|
+
- "docker build ." # whatever build command you use
|
28
|
+
run: &run
|
29
|
+
- "echo Running Hello World!"
|
30
|
+
test: &test
|
31
|
+
- "rspec" # whatever test command you use
|
32
|
+
# REQUIRED
|
33
|
+
commands:
|
34
|
+
build:
|
35
|
+
- *build
|
36
|
+
run:
|
37
|
+
- *run
|
38
|
+
test:
|
39
|
+
- *build
|
40
|
+
- *test
|
41
|
+
```
|
42
|
+
|
43
|
+
If you have the gem installed, then you can run your custom commands as follows:
|
44
|
+
|
45
|
+
```console
|
46
|
+
yapo exec build
|
47
|
+
# Will run: echo 'Building Hello World!' && docker build .'
|
48
|
+
yapo exec run
|
49
|
+
# Will run: echo 'echo Running Hello World!'
|
50
|
+
yapo exec test
|
51
|
+
# Will run: rspec
|
52
|
+
```
|
53
|
+
|
54
|
+
If you want to prepend a command to another custom command, you can add '-p' flag with the name of the prepend command. For example:
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
yapo exec custom_command_for_build -p docker
|
58
|
+
# Will run: 'docker-compose run web some bash script 1' && docker-compose run web echo 'some bash script 2'
|
59
|
+
```
|
60
|
+
|
61
|
+
## Examples
|
62
|
+
|
63
|
+
## Development
|
64
|
+
|
65
|
+
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.
|
66
|
+
|
67
|
+
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).
|
68
|
+
|
69
|
+
## Contributing
|
70
|
+
|
71
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/iufuenza/yapo.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "yapo"
|
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
data/exe/yapo
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
lib_path = File.expand_path('../lib', __dir__)
|
5
|
+
$:.unshift(lib_path) if !$:.include?(lib_path)
|
6
|
+
require 'yapo'
|
7
|
+
require 'yapo/cli'
|
8
|
+
|
9
|
+
Signal.trap('INT') do
|
10
|
+
warn("\n#{caller.join("\n")}: interrupted")
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
Yapo::CLI.start
|
16
|
+
rescue Yapo::CLI::Error => err
|
17
|
+
puts "ERROR: #{err.message}"
|
18
|
+
exit 1
|
19
|
+
end
|
data/lib/yapo.rb
ADDED
data/lib/yapo/cli.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'thor'
|
4
|
+
|
5
|
+
module Yapo
|
6
|
+
# Handle the application command line parsing
|
7
|
+
# and the dispatch to various command objects
|
8
|
+
#
|
9
|
+
# @api public
|
10
|
+
class CLI < Thor
|
11
|
+
# Error raised by this runner
|
12
|
+
Error = Class.new(StandardError)
|
13
|
+
|
14
|
+
desc 'version', 'yapo version'
|
15
|
+
def version
|
16
|
+
require_relative 'version'
|
17
|
+
puts "v#{Yapo::VERSION}"
|
18
|
+
end
|
19
|
+
map %w(--version -v) => :version
|
20
|
+
|
21
|
+
desc 'exec [COMMAND]', 'This command receives any bash script that you want to run in your project context.'
|
22
|
+
method_option :help, aliases: '-h', type: :boolean,
|
23
|
+
desc: 'Display usage information'
|
24
|
+
method_option :prepend, aliases: '-p', type: :string,
|
25
|
+
desc: 'Prepend a bash command to your commands.'
|
26
|
+
def exec(command, *args)
|
27
|
+
if command.empty? || options[:help]
|
28
|
+
invoke :help, ['exec']
|
29
|
+
else
|
30
|
+
require_relative 'commands/exec'
|
31
|
+
Yapo::Commands::Exec.new(command, options).execute
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/yapo/command.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module Yapo
|
6
|
+
class Command
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :command, :run
|
10
|
+
def_delegators :pastel
|
11
|
+
|
12
|
+
# Execute this command
|
13
|
+
#
|
14
|
+
# @api public
|
15
|
+
def execute(*)
|
16
|
+
raise(
|
17
|
+
NotImplementedError,
|
18
|
+
"#{self.class}##{__method__} must be implemented"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
# The external commands runner
|
23
|
+
def command(**options)
|
24
|
+
require 'tty-command'
|
25
|
+
TTY::Command.new(options)
|
26
|
+
end
|
27
|
+
|
28
|
+
# The output styler
|
29
|
+
def pastel(**options)
|
30
|
+
require 'pastel'
|
31
|
+
Pastel.new(options)
|
32
|
+
end
|
33
|
+
|
34
|
+
# File manipulation utility methods
|
35
|
+
def generator
|
36
|
+
require 'tty-file'
|
37
|
+
TTY::File
|
38
|
+
end
|
39
|
+
|
40
|
+
# Terminal platform and OS properties
|
41
|
+
def platform
|
42
|
+
require 'tty-platform'
|
43
|
+
TTY::Platform.new
|
44
|
+
end
|
45
|
+
|
46
|
+
# The interactive prompt
|
47
|
+
def prompt(**options)
|
48
|
+
require 'tty-prompt'
|
49
|
+
TTY::Prompt.new(options)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get terminal screen properties
|
53
|
+
def screen
|
54
|
+
require 'tty-screen'
|
55
|
+
TTY::Screen
|
56
|
+
end
|
57
|
+
|
58
|
+
# The unix which utility
|
59
|
+
def which(*args)
|
60
|
+
require 'tty-which'
|
61
|
+
TTY::Which.which(*args)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Check if executable exists
|
65
|
+
def exec_exist?(*args)
|
66
|
+
require 'tty-which'
|
67
|
+
TTY::Which.exist?(*args)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
require_relative '../helpers/teletype'
|
5
|
+
require_relative '../helpers/commands'
|
6
|
+
require_relative '../helpers/validations'
|
7
|
+
|
8
|
+
module Yapo
|
9
|
+
module Commands
|
10
|
+
class Exec < Yapo::Command
|
11
|
+
def initialize(command, options)
|
12
|
+
@command = command
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
16
|
+
def execute(input: $stdin, output: $stdout)
|
17
|
+
begin
|
18
|
+
commands_helper = Yapo::Helpers::Commands.new
|
19
|
+
validations_helper = Yapo::Helpers::Validations.new
|
20
|
+
|
21
|
+
validations_helper.verify_version
|
22
|
+
if @options[:prepend] && !@command.nil?
|
23
|
+
commands = commands_helper.prepend_commands(@options[:prepend], @command)
|
24
|
+
else
|
25
|
+
commands = commands_helper.get_commands_for(@command)
|
26
|
+
end
|
27
|
+
|
28
|
+
if commands.nil?
|
29
|
+
msg = "You must include an entry for #{@command} in .yapo.yml."
|
30
|
+
raise Yapo::Helpers::CustomErrors::ValidationError.new(nil, msg)
|
31
|
+
else
|
32
|
+
Yapo::Helpers::Teletype.new.bash_commands(commands)
|
33
|
+
end
|
34
|
+
|
35
|
+
output.puts "OK"
|
36
|
+
rescue Yapo::Helpers::CustomErrors::ValidationError
|
37
|
+
output.puts "ERROR:ValidationError"
|
38
|
+
rescue Yapo::Helpers::CustomErrors::SyntaxError
|
39
|
+
output.puts "ERROR:SyntaxError"
|
40
|
+
rescue Yapo::Helpers::CustomErrors::CommandError
|
41
|
+
output.puts "ERROR:CommandError"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Yapo
|
4
|
+
module Config
|
5
|
+
class Configurations
|
6
|
+
YAPO_HOME = File.realpath(File.join(File.dirname(__FILE__), '..', '..'))
|
7
|
+
DEFAULT_FILE = File.join(YAPO_HOME, 'yapo', 'config', 'default.yml')
|
8
|
+
CURRENT_CONFIG_FILE = File.expand_path(".yapo.yml", Dir.pwd)
|
9
|
+
|
10
|
+
attr_reader :configurations
|
11
|
+
|
12
|
+
def self.load
|
13
|
+
new.load
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@configurations = {}
|
18
|
+
end
|
19
|
+
|
20
|
+
def load
|
21
|
+
if File.exist?(CURRENT_CONFIG_FILE)
|
22
|
+
load_file(CURRENT_CONFIG_FILE)
|
23
|
+
else
|
24
|
+
load_file(DEFAULT_FILE)
|
25
|
+
end
|
26
|
+
|
27
|
+
@configurations
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def load_file(path)
|
33
|
+
if File.exist?(path)
|
34
|
+
@configurations = YAML.load_file(path)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
version: '0.1.0'
|
2
|
+
|
3
|
+
# OPTIONAL
|
4
|
+
build_web_cmds: &build_web_cmds
|
5
|
+
- "docker volume create some_volume"
|
6
|
+
- "docker-compose up --build web"
|
7
|
+
|
8
|
+
build_all_cmds: &build_all_cmds
|
9
|
+
- "docker volume create some_volume"
|
10
|
+
- "docker-compose up --build web"
|
11
|
+
|
12
|
+
run_cmds: &run_cmds
|
13
|
+
- "docker-compose up web"
|
14
|
+
|
15
|
+
remove_server_pid_cmds: &remove_server_pid_cmds
|
16
|
+
- "rm -f /sylvester/tmp/pids/server.pid"
|
17
|
+
|
18
|
+
docker_compose_run: &docker_compose_run
|
19
|
+
- "docker-compose run web"
|
20
|
+
|
21
|
+
test_cmds: &test_cmds
|
22
|
+
- "docker-compose run web bundle exec rspec"
|
23
|
+
|
24
|
+
exec_cmds: &exec_cmds
|
25
|
+
- "echo 'exec something'"
|
26
|
+
|
27
|
+
hello: &hello
|
28
|
+
- "echo 'hello'"
|
29
|
+
|
30
|
+
world: &world
|
31
|
+
- "echo 'world'"
|
32
|
+
|
33
|
+
# REQUIRED
|
34
|
+
commands:
|
35
|
+
build:
|
36
|
+
- *remove_server_pid_cmds
|
37
|
+
- *build_web_cmds
|
38
|
+
|
39
|
+
run:
|
40
|
+
- *run_cmds
|
41
|
+
|
42
|
+
exec:
|
43
|
+
- *exec_cmds
|
44
|
+
|
45
|
+
test:
|
46
|
+
- *test_cmds
|
47
|
+
|
48
|
+
hello:
|
49
|
+
- *hello
|
50
|
+
- *world
|
51
|
+
- ["echo 'sipo'"]
|
52
|
+
|
53
|
+
prepends:
|
54
|
+
docker:
|
55
|
+
command: *docker_compose_run
|
@@ -0,0 +1,59 @@
|
|
1
|
+
version: '0.1.0'
|
2
|
+
# OPTIONAL
|
3
|
+
build: &build
|
4
|
+
- "echo You have to add a 'build' entry in .yapo.yml"
|
5
|
+
|
6
|
+
run: &run
|
7
|
+
- "echo You have to add a 'run' entry in .yapo.yml"
|
8
|
+
|
9
|
+
exec: &exec
|
10
|
+
- "echo You have to add a 'exec' entry in .yapo.yml"
|
11
|
+
|
12
|
+
test: &test
|
13
|
+
- "echo You have to add a 'test' entry in .yapo.yml"
|
14
|
+
|
15
|
+
testing_command: &testing_command
|
16
|
+
- "echo This command is for test only."
|
17
|
+
- "echo Testing..."
|
18
|
+
|
19
|
+
testing_prepend: &testing_prepend
|
20
|
+
- "echo This prepend is for test only."
|
21
|
+
|
22
|
+
empty_testing_command: &empty_testing_command
|
23
|
+
|
24
|
+
incomplete_bash_command: &incomplete_bash_command
|
25
|
+
- "docker-compose invalid"
|
26
|
+
|
27
|
+
invalid_bash_command: &invalid_bash_command
|
28
|
+
- "invalid bash command"
|
29
|
+
|
30
|
+
# REQUIRED
|
31
|
+
commands:
|
32
|
+
build:
|
33
|
+
- *build
|
34
|
+
|
35
|
+
run:
|
36
|
+
- *run
|
37
|
+
|
38
|
+
exec:
|
39
|
+
- *exec
|
40
|
+
|
41
|
+
test:
|
42
|
+
- *test
|
43
|
+
|
44
|
+
testing_command:
|
45
|
+
- *testing_command
|
46
|
+
|
47
|
+
empty_testing_command:
|
48
|
+
- *empty_testing_command
|
49
|
+
|
50
|
+
incomplete_bash_command:
|
51
|
+
- *incomplete_bash_command
|
52
|
+
|
53
|
+
invalid_bash_command:
|
54
|
+
- *invalid_bash_command
|
55
|
+
|
56
|
+
prepends:
|
57
|
+
testing_prepend:
|
58
|
+
command:
|
59
|
+
- *testing_prepend
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './custom_errors'
|
4
|
+
|
5
|
+
module Yapo
|
6
|
+
module Helpers
|
7
|
+
class Commands
|
8
|
+
def get_commands_for(command_name)
|
9
|
+
begin
|
10
|
+
Yapo.configurations['commands'][command_name] unless
|
11
|
+
Yapo.configurations['commands'][command_name].nil?
|
12
|
+
rescue StandardError => e
|
13
|
+
raise Yapo::Helpers::CustomErrors::SyntaxError, e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def prepend_commands(prepend, command_name)
|
18
|
+
begin
|
19
|
+
commands = get_commands_for(command_name)
|
20
|
+
prepend_cmd = Yapo.configurations['prepends'][prepend]['command'].first unless
|
21
|
+
Yapo.configurations['prepends'].nil? ||
|
22
|
+
Yapo.configurations['prepends'][prepend].nil?
|
23
|
+
commands.first.map { |e| "#{prepend_cmd.first} #{e}" }
|
24
|
+
rescue StandardError => e
|
25
|
+
raise Yapo::Helpers::CustomErrors::SyntaxError, e
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../command'
|
4
|
+
|
5
|
+
module Yapo
|
6
|
+
module Helpers
|
7
|
+
module CustomErrors
|
8
|
+
class ErrorMessage < Yapo::Command
|
9
|
+
def initialize
|
10
|
+
end
|
11
|
+
|
12
|
+
def print(message)
|
13
|
+
puts pastel.red(message)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class ValidationError < StandardError
|
18
|
+
attr_reader :original
|
19
|
+
|
20
|
+
def initialize(exception = nil, msg)
|
21
|
+
@original = exception
|
22
|
+
ErrorMessage.new.print(message(msg))
|
23
|
+
end
|
24
|
+
|
25
|
+
def message(msg = nil)
|
26
|
+
"#{msg}\n"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class SyntaxError < StandardError
|
31
|
+
attr_reader :original
|
32
|
+
|
33
|
+
def initialize(exception = nil)
|
34
|
+
@original = exception
|
35
|
+
ErrorMessage.new.print(message)
|
36
|
+
end
|
37
|
+
|
38
|
+
def message
|
39
|
+
"You have a syntax error in your .yapo.yml file.\n" \
|
40
|
+
"#{@original}\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class CommandError < RuntimeError
|
45
|
+
attr_reader :params, :exit_status, :out, :err
|
46
|
+
|
47
|
+
def initialize(command, result, *args)
|
48
|
+
@command = command
|
49
|
+
@params = *args
|
50
|
+
@exit_status = result.exit_status
|
51
|
+
@out = result.out
|
52
|
+
@err = result.err
|
53
|
+
ErrorMessage.new.print(message)
|
54
|
+
end
|
55
|
+
|
56
|
+
def message
|
57
|
+
"The command you are tying to execute is not valid. Please verify it works in your terminal first.\n" \
|
58
|
+
"Running \"#{@command}\" failed with exit status #{@exit_status}.\n" \
|
59
|
+
" params: #{@params}\n" \
|
60
|
+
" std out: #{@out}\n" \
|
61
|
+
" std err: #{@err}\n"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class TimeoutError < RuntimeError
|
66
|
+
attr_reader :params, :out, :err
|
67
|
+
|
68
|
+
def initialize(command, timeout, result, *args)
|
69
|
+
@command = command
|
70
|
+
@params = *args
|
71
|
+
@timeout = timeout
|
72
|
+
@out = result.out
|
73
|
+
@err = result.err
|
74
|
+
super(message)
|
75
|
+
end
|
76
|
+
|
77
|
+
def message
|
78
|
+
"Running \"#{@command}\" timed out after #{@timeout} seconds.\n" \
|
79
|
+
" params: #{@params}\n" \
|
80
|
+
" std out: #{@out}\n" \
|
81
|
+
" std err: #{@err}\n"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class ErrorResult
|
86
|
+
attr_reader :exit_status, :out, :err
|
87
|
+
|
88
|
+
def initialize(exit_status, out, err)
|
89
|
+
@exit_status = exit_status
|
90
|
+
@out = out
|
91
|
+
@err = err
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './custom_errors'
|
4
|
+
require_relative '../command'
|
5
|
+
|
6
|
+
module Yapo
|
7
|
+
module Helpers
|
8
|
+
class Teletype < Yapo::Command
|
9
|
+
def initialize
|
10
|
+
@cmd = command(printer: :quiet)
|
11
|
+
end
|
12
|
+
|
13
|
+
def bash_commands(list)
|
14
|
+
bash_command(list.join(' && '))
|
15
|
+
end
|
16
|
+
|
17
|
+
def bash_command(script, *args)
|
18
|
+
begin
|
19
|
+
puts pastel.green("Executing: #{script}")
|
20
|
+
result = @cmd.run!(script, *args)
|
21
|
+
cmd = TTY::Command.new
|
22
|
+
|
23
|
+
if result.failure? && !result.exit_status.nil?
|
24
|
+
raise Yapo::Helpers::CustomErrors::CommandError.new(script, result, *args)
|
25
|
+
end
|
26
|
+
result
|
27
|
+
rescue StandardError => e
|
28
|
+
result = Yapo::Helpers::CustomErrors::ErrorResult.new(1, "", e)
|
29
|
+
raise Yapo::Helpers::CustomErrors::CommandError.new(script, result, *args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './custom_errors'
|
4
|
+
|
5
|
+
module Yapo
|
6
|
+
module Helpers
|
7
|
+
class Validations
|
8
|
+
def verify_version
|
9
|
+
version_match = Yapo.configurations['version'] == VERSION
|
10
|
+
unless version_match
|
11
|
+
msg = "You have an outdated version of Yapo. " \
|
12
|
+
"Please verify that the version specified in .yapo.yml match with your gem version.\n" \
|
13
|
+
"To check your gem version, run: yapo version"
|
14
|
+
raise Yapo::Helpers::CustomErrors::ValidationError.new(nil, msg)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/yapo/version.rb
ADDED
data/yapo.gemspec
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "yapo/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "yapo"
|
8
|
+
spec.version = Yapo::VERSION
|
9
|
+
spec.authors = ["Ignacio Fuenzalida"]
|
10
|
+
spec.email = ["icfuenza@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "CLI commands generator"
|
13
|
+
spec.homepage = "https://github.com/iufuenza/yapo"
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "tty-command", "~> 0.7.0"
|
25
|
+
spec.add_dependency "pastel", "~> 0.7.2"
|
26
|
+
spec.add_dependency "thor", "~> 0.19.4"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yapo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ignacio Fuenzalida
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: tty-command
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.7.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.7.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pastel
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.7.2
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.2
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.19.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.19.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.16'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- icfuenza@gmail.com
|
100
|
+
executables:
|
101
|
+
- yapo
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- Gemfile.lock
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- exe/yapo
|
115
|
+
- lib/yapo.rb
|
116
|
+
- lib/yapo/cli.rb
|
117
|
+
- lib/yapo/command.rb
|
118
|
+
- lib/yapo/commands/exec.rb
|
119
|
+
- lib/yapo/config/configurations.rb
|
120
|
+
- lib/yapo/config/default.example.yml
|
121
|
+
- lib/yapo/config/default.yml
|
122
|
+
- lib/yapo/helpers/commands.rb
|
123
|
+
- lib/yapo/helpers/custom_errors.rb
|
124
|
+
- lib/yapo/helpers/teletype.rb
|
125
|
+
- lib/yapo/helpers/validations.rb
|
126
|
+
- lib/yapo/version.rb
|
127
|
+
- yapo.gemspec
|
128
|
+
homepage: https://github.com/iufuenza/yapo
|
129
|
+
licenses: []
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - ">="
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.5.2.3
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: CLI commands generator
|
151
|
+
test_files: []
|