rubycmd 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/Core.rb +74 -0
- data/lib/rubycmd.rb +2 -0
- data/lib/tools.rb +58 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 234cdcd94db63e24277f2ecc09e6d4724893229a583335153dd218c9c555d9b5
|
4
|
+
data.tar.gz: ba29f1bb49926e29c5d4d18fa403d1f48a96050a8341429d3defb2804b7c4198
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 805fbfe869ee972e259df052d5f962fff74cb579716363f0867a004f1b81b55fde73d2e5019197395b1f2ffe4e24d84d340eaad4984d8013a4ebcb54b91b241c
|
7
|
+
data.tar.gz: d5bf7ff7d12f986b04bc7d1e90a668ab1dc67532bf855e05321ace242559918813c9aeb62f3cceb227d48b7fb44fc343b6c6c45c7ee5e3a3f2b974ef1573681e
|
data/lib/Core.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
class Cmd
|
2
|
+
CLASS = self
|
3
|
+
def initialize (prompt: "cmd> ", banner: "" , msg: "")
|
4
|
+
@prompt = prompt
|
5
|
+
@banner = banner
|
6
|
+
@msg = msg
|
7
|
+
end
|
8
|
+
def loopcmd
|
9
|
+
Tools.print_filget @banner if @banner
|
10
|
+
Tools.print_msg @msg unless @msg.empty?
|
11
|
+
while true
|
12
|
+
begin
|
13
|
+
Tools.print @prompt
|
14
|
+
command = gets.chomp
|
15
|
+
if ["exit" , "quit"].include?(command)
|
16
|
+
break
|
17
|
+
elsif command.empty?
|
18
|
+
nil
|
19
|
+
elsif command.start_with?("help")
|
20
|
+
handle_help(command)
|
21
|
+
else
|
22
|
+
handle_command(command)
|
23
|
+
end
|
24
|
+
rescue Interrupt
|
25
|
+
break
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def handle_command (cmd)
|
33
|
+
begin
|
34
|
+
command , args = Tools.parse_args(cmd)
|
35
|
+
if (args.empty? == false)
|
36
|
+
eval("do_#{command} (#{args})")
|
37
|
+
else
|
38
|
+
eval("do_#{command}")
|
39
|
+
end
|
40
|
+
rescue NameError
|
41
|
+
Tools.CommandNotFourd (cmd)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_help (cmd)
|
46
|
+
# Detecting help command without any argument
|
47
|
+
if cmd.split(" ").size != 1
|
48
|
+
if ["exit" , "quit"].include?(cmd.sub("help " , ""))
|
49
|
+
Tools.print "\nExit the program\n\n"
|
50
|
+
else
|
51
|
+
begin
|
52
|
+
eval("#{cmd.sub(" " , "_")}")
|
53
|
+
rescue NameError
|
54
|
+
Tools.CommandNotFourd(cmd.sub("help " , ""))
|
55
|
+
end
|
56
|
+
end
|
57
|
+
else
|
58
|
+
commands = []
|
59
|
+
(Cmd.private_instance_methods - Cmd.private_methods).each do |cmd|
|
60
|
+
cmd = cmd.to_s
|
61
|
+
if cmd.start_with?("do_")
|
62
|
+
commands.push(cmd)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
Tools.print_help "Avalable commands :\n"
|
66
|
+
commands.each do |cmd|
|
67
|
+
cmd.sub!("do_" , "")
|
68
|
+
Tools.print_help "#{cmd}\t\t\t\t"
|
69
|
+
eval("help_#{cmd}")
|
70
|
+
end
|
71
|
+
Tools.print "\n"
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/rubycmd.rb
ADDED
data/lib/tools.rb
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'colorize'
|
2
|
+
require 'ruby_figlet'
|
3
|
+
|
4
|
+
class Tools
|
5
|
+
def self.parse_args (str)
|
6
|
+
command_pattern = /^[a-zA-Z]+/
|
7
|
+
command = str.scan(command_pattern)[0]
|
8
|
+
args_pattern = /-{1,2}([a-z-]+)[=|\s](\S+)/
|
9
|
+
parsed = str.scan(args_pattern)
|
10
|
+
args = Hash.new
|
11
|
+
parsed.each do |arg|
|
12
|
+
args[arg[0].to_sym] = arg[1]
|
13
|
+
end
|
14
|
+
return command , args
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.figlet (text , font)
|
18
|
+
RubyFiglet::Figlet.new(text , font)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.print_filget (figlet)
|
22
|
+
puts figlet.to_s.red
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.print_help (text)
|
26
|
+
$stdout.write "\n[@] ".blue+text.white
|
27
|
+
$stdout.flush()
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.print_success (text)
|
31
|
+
$stdout.write "[+] ".green+text+"\n".white
|
32
|
+
$stdout.flush()
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.print_warning (text)
|
36
|
+
$stdout.write "[!] ".yellow+text+"\n".white
|
37
|
+
$stdout.flush()
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.print_error (text)
|
41
|
+
$stdout.write "[!!!] ".red+text+"\n".white
|
42
|
+
$stdout.flush()
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.print_msg (text)
|
46
|
+
$stdout.write "\n\n[~] ".green+text+"\n".white
|
47
|
+
$stdout.flush()
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.print (text)
|
51
|
+
$stdout.write text.white
|
52
|
+
$stdout.flush()
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.CommandNotFourd (cmd)
|
56
|
+
Tools.print_error("'#{cmd}' command not found.\n")
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubycmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pooria zandvakili
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a gem to create shell apps like cmd library in python
|
14
|
+
email: pooriazandvakili@tutamail.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/Core.rb
|
20
|
+
- lib/rubycmd.rb
|
21
|
+
- lib/tools.rb
|
22
|
+
homepage: https://github.com/PooriaZandvakili/rubycmd
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.3.3
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: RubyCmd
|
45
|
+
test_files: []
|