invocker 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/invocker +14 -0
- data/lib/invocker/config.rb +5 -0
- data/lib/invocker/db.rb +20 -0
- data/lib/invocker/main.rb +53 -0
- data/lib/invocker/migrate.rb +13 -0
- data/lib/invocker/model.rb +12 -0
- data/lib/invocker/optpare.rb +83 -0
- data/lib/invocker/optparsr_options/config.rb +25 -0
- data/lib/invocker/optparsr_options/database.rb +14 -0
- data/lib/invocker/optparsr_options/execute.rb +9 -0
- data/lib/invocker.rb +5 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2e160117bc2121ec061bfe68836a4d225ae62c951a49e806d01d0ecce5aba2c6
|
4
|
+
data.tar.gz: e78164d1b0ecb847dbcfd68ef856a788ca8969a51437aed17e07a52908a314e0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a850519730f7c796404dfa62708912177cba56bf3e7c8ac13bcc5b0a35cda67e82b47d84922d22c1316050068e7af5652d1ad126fc1cb0c798b36b1b24d614ea
|
7
|
+
data.tar.gz: fd65009697c3793edfa7773a1fb40fc0e50a3464d2721e93547f54de306767ba8f1a95a8e96c8cc697b0f72780d80ee94fd3fbea614a0b68e1824396d2df93e4
|
data/bin/invocker
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$:.unshift File.dirname(__FILE__) + "/../lib"
|
3
|
+
require 'optparse'
|
4
|
+
require 'invocker'
|
5
|
+
require 'invocker/main'
|
6
|
+
|
7
|
+
|
8
|
+
begin
|
9
|
+
Invocker::Console.new.start
|
10
|
+
rescue OptionParser::ParseError => ex
|
11
|
+
STDERR.puts "!! #{ex.message}"
|
12
|
+
puts "** use `#{File.basename($0)} --help` for more details..."
|
13
|
+
exit 1
|
14
|
+
end
|
data/lib/invocker/db.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Invocker
|
2
|
+
require 'active_record'
|
3
|
+
require 'sqlite3'
|
4
|
+
require 'invocker/config'
|
5
|
+
|
6
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: Invocker::Config::DATABASE_HOST)
|
7
|
+
class Database
|
8
|
+
class << self
|
9
|
+
def create
|
10
|
+
ENV["mode"] = 'create'
|
11
|
+
require 'invocker/migrate'
|
12
|
+
end
|
13
|
+
|
14
|
+
def drop
|
15
|
+
ENV["mode"] = 'drop'
|
16
|
+
require 'invocker/migrate'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'invocker/db'
|
2
|
+
require 'invocker/optpare'
|
3
|
+
require 'invocker/model'
|
4
|
+
|
5
|
+
module Invocker
|
6
|
+
class Console
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
invocker = Invocker::OptparsrInvocker.new
|
10
|
+
@options = invocker.parse(ARGV)
|
11
|
+
end
|
12
|
+
|
13
|
+
def start
|
14
|
+
configs if @options.config
|
15
|
+
executes if @options.execute
|
16
|
+
Invocker::Database.create if @options.database == :create
|
17
|
+
Invocker::Database.drop if @options.database == :drop
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def configs
|
23
|
+
alias_key = @options.config_message
|
24
|
+
key = alias_key.gsub "alias.", ''
|
25
|
+
|
26
|
+
case @options.config_type
|
27
|
+
when 'create'
|
28
|
+
command = ARGV[1]
|
29
|
+
Invocker::Model::Command.create key: key, command: command
|
30
|
+
puts "Done!"
|
31
|
+
when 'delete'
|
32
|
+
command = Invocker::Model::Command.find_by(key: key)
|
33
|
+
return puts 'Not thing unset' if command.blank?
|
34
|
+
|
35
|
+
command.destroy
|
36
|
+
when 'list'
|
37
|
+
puts "num | id | key | command"
|
38
|
+
Invocker::Model::Command.all.each_with_index do |command, num|
|
39
|
+
puts "#{num + 1}. | #{command.id} | #{command.key} | #{command.command}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def executes
|
45
|
+
# alias_key = @options.config_message
|
46
|
+
# puts alias_key
|
47
|
+
# key = alias_key.gsub "alias.", ''
|
48
|
+
# puts ARGV
|
49
|
+
command = Invocker::Model::Command.find_by(key: ARGV[1])
|
50
|
+
exec command.command
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
mode = ENV.fetch("mode")
|
2
|
+
|
3
|
+
class CommandTable < ActiveRecord::Migration[5.2]
|
4
|
+
def change
|
5
|
+
create_table :commands do |table|
|
6
|
+
table.string :key
|
7
|
+
table.string :command
|
8
|
+
table.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
CommandTable.migrate(:up) if mode == "create"
|
13
|
+
CommandTable.migrate(:down) if mode == "drop"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Invocker
|
2
|
+
module Model
|
3
|
+
require 'active_record'
|
4
|
+
require 'sqlite3'
|
5
|
+
require 'invocker/config'
|
6
|
+
|
7
|
+
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: Invocker::Config::DATABASE_HOST)
|
8
|
+
class Command < ActiveRecord::Base
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
|
2
|
+
require 'optparse'
|
3
|
+
require 'optparse/time'
|
4
|
+
require 'ostruct'
|
5
|
+
require 'pp'
|
6
|
+
require 'invocker/optparsr_options/config'
|
7
|
+
require 'invocker/optparsr_options/execute'
|
8
|
+
require 'invocker/optparsr_options/database'
|
9
|
+
|
10
|
+
module Invocker
|
11
|
+
class OptparsrInvocker
|
12
|
+
Version = '1.0.0'
|
13
|
+
|
14
|
+
CODES = %w[iso-2022-jp shift_jis euc-jp utf8 binary]
|
15
|
+
CODE_ALIASES = { "jis" => "iso-2022-jp", "sjis" => "shift_jis" }
|
16
|
+
|
17
|
+
class ScriptOptions
|
18
|
+
attr_accessor :config, :config_type, :config_message, :database, :execute
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
self.config = false
|
22
|
+
self.execute = false
|
23
|
+
end
|
24
|
+
|
25
|
+
def define_options(parser)
|
26
|
+
init_config parser
|
27
|
+
# add additional options
|
28
|
+
Invocker::OptpareOptions::Configs.define(parser, self)
|
29
|
+
Invocker::OptpareOptions::Executes.define(parser, self)
|
30
|
+
Invocker::OptpareOptions::Databases.define(parser, self)
|
31
|
+
end_config parser
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def init_config parser
|
37
|
+
parser.banner = "Usage: example.rb [options]"
|
38
|
+
parser.separator ""
|
39
|
+
parser.separator "Specific options:"
|
40
|
+
|
41
|
+
case ARGV.first
|
42
|
+
when "config"
|
43
|
+
self.config = true
|
44
|
+
when "exec"
|
45
|
+
self.execute = true
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def end_config parser
|
50
|
+
parser.separator ""
|
51
|
+
parser.separator "Common options:"
|
52
|
+
# No argument, shows at tail. This will print an options summary.
|
53
|
+
# Try it and see!
|
54
|
+
parser.on_tail("-h", "--help", "Show this message") do
|
55
|
+
puts parser
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
# Another typical switch to print the version.
|
59
|
+
parser.on_tail("--version", "Show version") do
|
60
|
+
puts Version
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Return a structure describing the options.
|
68
|
+
#
|
69
|
+
def parse(args)
|
70
|
+
# The options specified on the command line will be collected in
|
71
|
+
# *options*.
|
72
|
+
|
73
|
+
@options = ScriptOptions.new
|
74
|
+
@args = OptionParser.new do |parser|
|
75
|
+
@options.define_options(parser)
|
76
|
+
parser.parse!(args)
|
77
|
+
end
|
78
|
+
@options
|
79
|
+
end
|
80
|
+
|
81
|
+
attr_reader :parser, :options
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Invocker
|
2
|
+
module OptpareOptions
|
3
|
+
class Executes
|
4
|
+
def self.define(parser, script_options)
|
5
|
+
# return unless script_options.config
|
6
|
+
|
7
|
+
# Specifies an optional option argument
|
8
|
+
parser.on("-c", "--create [COMMAND]", "alias.key 'your short command'", "Your config alias") do |message|
|
9
|
+
script_options.config_message = message || ''
|
10
|
+
script_options.config_type = 'create'
|
11
|
+
end
|
12
|
+
|
13
|
+
parser.on("-d", "--delete [COMMAND]", "alias.[key of command] eg: alias.ssh_10.10.10.10", "your key you want remove") do |message|
|
14
|
+
script_options.config_message = message || ''
|
15
|
+
script_options.config_type = 'delete'
|
16
|
+
end
|
17
|
+
|
18
|
+
parser.on("-l", "--list [COMMAND]", "alias.[key of command] eg: alias.ssh_10.10.10.10", "your key you want remove") do |message|
|
19
|
+
script_options.config_message = message || ''
|
20
|
+
script_options.config_type = 'list'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Invocker
|
2
|
+
module OptpareOptions
|
3
|
+
class Databases
|
4
|
+
def self.define(parser, script_options)
|
5
|
+
# return unless script_options.execute
|
6
|
+
|
7
|
+
options = [:create, :drop, :upall, :downall ]
|
8
|
+
parser.on("--db [TYPE]", options, options, "Select transfer type (create, :drop, :upall, :downall)") do |db|
|
9
|
+
script_options.database = db
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/invocker.rb
ADDED
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: invocker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dang Thanh Tung
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-06-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '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'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
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
|
+
description: A magic for life developer.
|
42
|
+
email: dangthanhtung.open@gmail.com
|
43
|
+
executables:
|
44
|
+
- invocker
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- bin/invocker
|
49
|
+
- lib/invocker.rb
|
50
|
+
- lib/invocker/config.rb
|
51
|
+
- lib/invocker/db.rb
|
52
|
+
- lib/invocker/main.rb
|
53
|
+
- lib/invocker/migrate.rb
|
54
|
+
- lib/invocker/model.rb
|
55
|
+
- lib/invocker/optpare.rb
|
56
|
+
- lib/invocker/optparsr_options/config.rb
|
57
|
+
- lib/invocker/optparsr_options/database.rb
|
58
|
+
- lib/invocker/optparsr_options/execute.rb
|
59
|
+
homepage: https://rubygems.org/gems/hola
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubygems_version: 3.2.3
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Invocker, this is magic!
|
82
|
+
test_files: []
|