termory 0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8d8bbd6e53c1967f571b43197505ea87902fe6238e89067a44ec215822c0bda6
4
+ data.tar.gz: 3ecadc6d187637f8f92cecd004068e718c0b2ad2db92987748b772592bf6e633
5
+ SHA512:
6
+ metadata.gz: 140914033b2784660076c272589eb1fd6f50b6ec1b0fea2e57b929e8d4e9230157f03f02d0561bcf9f6813d7c4080374dbcb58756098778b336cd192d428b6a8
7
+ data.tar.gz: 208dffa2cef3f4c200f5f58c7da56664f0479a954d7c487d3b45f9e3540e215d34c2dfa22b66ed728c7b01bd3a65bc1559687a35a94afc89352ed18929a9b93c
data/bin/termory ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.dirname(__FILE__) + "/../lib"
3
+ require 'optparse'
4
+ require 'termory'
5
+
6
+ begin
7
+ Termory::Console.new.start
8
+ rescue OptionParser::ParseError => ex
9
+ STDERR.puts "!! #{ex.message}"
10
+ puts "** use `#{File.basename($0)} --help` for more details..."
11
+ exit 1
12
+ end
@@ -0,0 +1,5 @@
1
+ module Termory
2
+ class Config
3
+ DATABASE_HOST = File.join(Dir.home, ".termory.db")
4
+ end
5
+ end
data/lib/termory/db.rb ADDED
@@ -0,0 +1,20 @@
1
+ module Termory
2
+ require 'active_record'
3
+ require 'sqlite3'
4
+ require 'termory/config'
5
+
6
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: Termory::Config::DATABASE_HOST)
7
+ class Database
8
+ class << self
9
+ def create
10
+ ENV["mode"] = 'create'
11
+ require 'termory/migrate'
12
+ end
13
+
14
+ def drop
15
+ ENV["mode"] = 'drop'
16
+ require 'termory/migrate'
17
+ end
18
+ end
19
+ end
20
+ end
File without changes
@@ -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 Termory
2
+ module Model
3
+ require 'active_record'
4
+ require 'sqlite3'
5
+ require 'termory/config'
6
+
7
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: Termory::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 'termory/optparsr_options/config'
7
+ require 'termory/optparsr_options/execute'
8
+ require 'termory/optparsr_options/database'
9
+
10
+ module Termory
11
+ class OptparsrTermory
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
+ Termory::OptpareOptions::Configs.define(parser, self)
29
+ Termory::OptpareOptions::Executes.define(parser, self)
30
+ Termory::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 Termory
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 Termory
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
@@ -0,0 +1,9 @@
1
+ module Termory
2
+ module OptpareOptions
3
+ class Configs
4
+ def self.define(parser, script_options)
5
+ return unless script_options.execute
6
+ end
7
+ end
8
+ end
9
+ end
data/lib/termory.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'termory/db'
2
+ require 'termory/optpare'
3
+ require 'termory/model'
4
+
5
+ module Termory
6
+ class Console
7
+
8
+ def initialize
9
+ termory = Termory::OptparsrTermory.new
10
+ @options = termory.parse(ARGV)
11
+ end
12
+
13
+ def start
14
+ configs if @options.config
15
+ executes if @options.execute
16
+ Termory::Database.create if @options.database == :create
17
+ Termory::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
+ Termory::Model::Command.create key: key, command: command
30
+ puts "Done!"
31
+ when 'delete'
32
+ command = Termory::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
+ Termory::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 = Termory::Model::Command.find_by(key: ARGV[1])
50
+ exec command.command
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termory
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.0'
5
+ platform: ruby
6
+ authors:
7
+ - Dang Thanh Tung
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-06-06 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
+ - termory
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - bin/termory
49
+ - lib/termory.rb
50
+ - lib/termory/config.rb
51
+ - lib/termory/db.rb
52
+ - lib/termory/main.rb
53
+ - lib/termory/migrate.rb
54
+ - lib/termory/model.rb
55
+ - lib/termory/optpare.rb
56
+ - lib/termory/optparsr_options/config.rb
57
+ - lib/termory/optparsr_options/database.rb
58
+ - lib/termory/optparsr_options/execute.rb
59
+ homepage: https://github.com/lupca/termory
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: Termory, this is magic!
82
+ test_files: []