ezycli 1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7e64cd48f3f2a4fde16b8ba9db52814a63754c0507c34e5670768ad318f004f5
4
+ data.tar.gz: c4071c9cc1b7b323ccda055768298d088734c13dd11749736bc85acc6cc0808e
5
+ SHA512:
6
+ metadata.gz: 4283c2f58724ba17967e8c38dc0cceb30d8746f519d7e650145e3b1a7c8e432d3653399238e56a246e0cec2c97c42d67049cc601b60dc6fd34754420c093f133
7
+ data.tar.gz: beac34e32e949527128c52a923db2097927b42fe92a32342c7a1809f44d731c5c576873de754d023405e770d7781fc5682de389fc61f9254a8478c943c3c83c9
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ require "#{File.expand_path(File.dirname(__FILE__))}/../lib/cli.rb"
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # SETUP # DO NOT REMOVE ME # THIS SETS UP THE CORRECT COLORS AND LAYOUTS FOR THE APPLICATION
4
+ # Require the variables that make this application run.
5
+ require("#{File.expand_path(File.dirname(__FILE__))}/vars.rb")
6
+ require 'listen'
7
+ require 'active_support'
8
+ require 'active_support/core_ext'
9
+ require 'fileutils'
10
+
11
+ # COLORS!
12
+ def colorize(text, color = "default", bgColor = "default")
13
+ colors = {"default" => "38","black" => "30","red" => "31","green" => "32","brown" => "33", "blue" => "34", "purple" => "35",
14
+ "cyan" => "36", "gray" => "37", "dark gray" => "1;30", "light red" => "1;31", "light green" => "1;32", "yellow" => "1;33",
15
+ "light blue" => "1;34", "light purple" => "1;35", "light cyan" => "1;36", "white" => "1;37"}
16
+ bgColors = {"default" => "0", "black" => "40", "red" => "41", "green" => "42", "brown" => "43", "blue" => "44",
17
+ "purple" => "45", "cyan" => "46", "gray" => "47", "dark gray" => "100", "light red" => "101", "light green" => "102",
18
+ "yellow" => "103", "light blue" => "104", "light purple" => "105", "light cyan" => "106", "white" => "107"}
19
+ color_code = colors[color]
20
+ bgColor_code = bgColors[bgColor]
21
+ return "\033[#{bgColor_code};#{color_code}m#{text}\033[0m"
22
+ end
23
+
24
+ # Color mappings
25
+ def info
26
+ return colorize("[INFO] ", "green")
27
+ end
28
+ def warning
29
+ return colorize("[WARNING] ", "yellow")
30
+ end
31
+ def error
32
+ return colorize("[ERROR] ", "red")
33
+ end
34
+ def debug
35
+ return colorize("[DEBUG] ", "blue")
36
+ end
37
+
38
+ def exit_handler
39
+ if !@newline
40
+ puts ""
41
+ end
42
+ begin
43
+ save_history
44
+ rescue NoMethodError => e
45
+ puts "#{error}Unable to save history!"
46
+ end
47
+ puts "#{debug}Exiting ezyCLI"
48
+ puts "#{info}Have a great day!"
49
+ end
50
+
51
+ # END APPLICATION SETUP BLOCK #
52
+
53
+ # Start by first loading all known plugins. This reads the plugin from disk.
54
+ # TODO: Extend to allow plugin dependencies, i.e. load the plugins this one requires before loading this one.
55
+ unless File.directory?(File.expand_path("~/.ezycli/plugins"))
56
+ puts "#{info}Creating plugin directory"
57
+ FileUtils.mkdir_p(File.expand_path("~/.ezycli/plugins"))
58
+ end
59
+ unless File.directory?(File.expand_path("~/.ezycli/plugs/php"))
60
+ puts "#{info}Creating plugs directory"
61
+ FileUtils.mkdir_p(File.expand_path("~/.ezycli/plugs/php"))
62
+ end
63
+ def application_start
64
+ Dir["#{File.expand_path(File.dirname(__FILE__))}/plugins/*.rb"].sort.each do |file|
65
+ puts "#{debug}Loading application plugin #{File.basename(file, ".rb")}"
66
+ require file
67
+ @plugin_counter += 1
68
+ @plugin_array.push(File.basename(file))
69
+ begin
70
+ @plugin_help.push(plugin_help) unless @plugin_help.include? plugin_help
71
+ rescue NameError => e
72
+ # Do nothing if there's no such method
73
+ end
74
+ begin
75
+ @plugin_commands.merge!(plugin_commands)
76
+ rescue NameError => e
77
+ # Do nothing if theunlessre's no such method
78
+ end
79
+ begin
80
+ @plugin_associations.merge!(plugin_associations)
81
+ rescue NameError => e
82
+ # Do nothing if there's no such method
83
+ end
84
+ end
85
+ begin
86
+ load_history
87
+ rescue NoMethodError => e
88
+ puts "#{error}Unable to load history!"
89
+ end
90
+ puts "#{info}Attempting to load user plugins from #{File.expand_path(File.dirname("~/.ezycli/plugins"))}"
91
+ Dir["#{File.expand_path("~/.ezycli/plugins")}/*.rb"].sort.each do |file|
92
+ puts "#{debug}Loading user plugin #{File.basename(file, ".rb")}"
93
+ require file
94
+ @plugin_counter += 1
95
+ @plugin_array.push(File.basename(file))
96
+ begin
97
+ @plugin_help.push(plugin_help) unless @plugin_help.include? plugin_help
98
+ rescue NameError => e
99
+ # Do nothing if there's no such method
100
+ end
101
+ begin
102
+ @plugin_commands.merge!(plugin_commands)
103
+ rescue NameError => e
104
+ # Do nothing if there's no such method
105
+ end
106
+ begin
107
+ @plugin_associations.merge!(plugin_associations)
108
+ rescue NameError => e
109
+ # Do nothing if there's no such method
110
+ end
111
+ end
112
+ File.open("#{File.expand_path("~/.ezycli/plugs/php")}/hello-world.php", 'w') { |file| file.write("<?php \necho 'Hello, World!';\n") } unless File.file? "#{File.expand_path("~/.ezycli/plugs/php")}/hello-world.php"
113
+ File.open("#{File.expand_path("~/.ezycli/plugins")}/test.rb", 'w') { |file| file.write("def test_function\nputs 'This is a test plugin that was automatically generated when you first ran ezyCLI'\nend\n\n############ THESE FUNCTIONS MUST EXIST ############\n\ndef plugin_commands\n# This is where you tell ezyCLI about the plugins it's to use\nreturn {\"testme\" => \"test_function\"}\nend\n\ndef plugin_associations\n# This is where you tell ezyCLI about which plugins belong to which file. I'll eventually fix that.\nreturn \"test\" => [\"testme\"]\nend") } unless File.file? "#{File.expand_path("~/.ezycli/plugins")}/test.rb"
114
+ end
115
+
116
+ # Set the exit handler
117
+ at_exit {exit_handler}
118
+
119
+ # Boot the CLI and let the user know it's now ready to be used.
120
+ application_start
121
+ cli_is_ready
122
+ cli_loop
@@ -0,0 +1,66 @@
1
+ require "readline"
2
+
3
+ # What? you thought that the CLI also wouldn't be a plugin?
4
+ def cli_is_ready
5
+ puts "#{info}Loaded #{@plugin_counter} plugin(s)!"
6
+ puts "#{info}Welcome to the ezyCLI! _stuck? try 'help'"
7
+ end
8
+
9
+ def cli_loop
10
+ loop {
11
+ begin
12
+ input = Readline.readline("ezyCLI> ", true)
13
+ if input.instance_of? String
14
+ cli_cmd(input)
15
+ else
16
+ exit 0
17
+ end
18
+ rescue SystemExit, Interrupt => e
19
+ exit 0
20
+ end
21
+ }
22
+ end
23
+
24
+ def cli_cmd(cmd)
25
+ begin
26
+ case
27
+ when (cmd.include?("help"))
28
+ puts "help - Provides this help text"
29
+ puts "version - Shows the version of ezyCLI"
30
+ puts "exit - Exits ezyCLI"
31
+ puts @plugin_help
32
+ when (cmd.include?("exit"))
33
+ @newline = 0
34
+ exit 0
35
+ when (cmd.include?("version"))
36
+ puts "ezyCLI version 0.2.3 DEV"
37
+ when (cmd.empty?)
38
+ # blank command...
39
+ else
40
+ c = cmd.split(" ")
41
+ if c.count == 1
42
+ begin
43
+ send(@plugin_commands["#{cmd}"])
44
+ rescue ArgumentError => e
45
+ puts "#{warning}Wrong number of arguments given"
46
+ rescue TypeError => e
47
+ puts "#{warning}Unknown command: #{cmd}"
48
+ end
49
+ else
50
+ args = Array.new
51
+ begin
52
+ c[1..-1].each do |arg|
53
+ args.push(arg)
54
+ end
55
+ send(@plugin_commands["#{c[0]}"], *args)
56
+ rescue ArgumentError => e
57
+ puts "#{warning}Wrong number of arguments given"
58
+ rescue TypeError => e
59
+ puts "#{warning}Unknown command: #{cmd}"
60
+ end
61
+ end
62
+ end
63
+ rescue NoMethodError => e
64
+ # Nothing doing
65
+ end
66
+ end
@@ -0,0 +1,33 @@
1
+ require 'yaml'
2
+
3
+ def save_history
4
+ File.open("#{File.expand_path("~/.ezycli")}/.ezycli_history", 'w') { |f| f.write(YAML.dump(Readline::HISTORY.to_a))}
5
+ puts "#{info}Wrote history to #{File.expand_path("~/.ezycli")}/.ezycli_history"
6
+ end
7
+
8
+ def load_history
9
+ if File.file?("#{File.expand_path("~/.ezycli")}/.ezycli_history")
10
+ conf = YAML.load_file "#{File.expand_path("~/.ezycli")}/.ezycli_history"
11
+ conf.each do |line|
12
+ if line.present? and !line.include? "exit"
13
+ Readline::HISTORY.push(line)
14
+ end
15
+ end
16
+ else
17
+ puts "#{info}Initialized empty history"
18
+ end
19
+ end
20
+
21
+ ############ THESE FUNCTIONS MUST EXIST ############
22
+
23
+ def plugin_commands
24
+ # I know, I know. I'll clean it up later. shhhhh
25
+ return {"save" => "save_history", "reset" => "load_history"}
26
+ end
27
+
28
+ def plugin_associations
29
+ # see the above comment.
30
+ return "history" => ["save", "reset"]
31
+ end
32
+
33
+ ########### THESE FUNCTIONS MUST EXIST ############
@@ -0,0 +1,47 @@
1
+ # Yes, the ability to load plugins is itself a plugin. You may also not unload the plugin loader. This is a hardcoded dep for the application to run correctly
2
+
3
+ def load_plugin(plugin_name)
4
+ if @plugin_associations["plugin_name"]
5
+ puts "#{error}Cowardly refusing to load a plugin that's already loaded"
6
+ else
7
+ begin
8
+ silence_warnings {load "#{File.expand_path("~/.ezycli/plugins")}/"+plugin_name+".rb"}
9
+ begin
10
+ @plugin_help.push(plugin_help) unless @plugin_help.include? plugin_help
11
+ rescue NameError => e
12
+ # Do nothing if there's no such method
13
+ end
14
+ begin
15
+ @plugin_commands.merge!(plugin_commands)
16
+ rescue NameError => e
17
+ # Do nothing if there's no such method
18
+ end
19
+ begin
20
+ @plugin_associations.merge!(plugin_associations)
21
+ rescue NameError => e
22
+ # Do nothing if there's no such method
23
+ end
24
+ puts "#{info}Loaded plugin #{plugin_name}"
25
+ rescue Exception => e
26
+ puts "#{warning}Failed to load plugin #{plugin_name}"
27
+ end
28
+ end
29
+ end
30
+
31
+ ############ THESE FUNCTIONS MUST EXIST ############
32
+
33
+ def plugin_help
34
+ return ["load - Loads a plugin"]
35
+ end
36
+
37
+ def plugin_commands
38
+ # I know, I know. I'll clean it up later. shhhhh
39
+ return {"load" => "load_plugin"}
40
+ end
41
+
42
+ def plugin_associations
43
+ # see the above comment.
44
+ return "load" => ["load"]
45
+ end
46
+
47
+ ########### THESE FUNCTIONS MUST EXIST ############
@@ -0,0 +1,45 @@
1
+ # WARNING: DO NOT MODIFY THIS FILE! I CANNOT BE MORE EXPLICIT!
2
+ # WARNING: THIS FILE LOADS THE RIGHT PLUG FOR THE LANGUAGE. *DO NOT TOUCH ME*!
3
+ def plug_exec(language, plugin_name)
4
+ io = IO.popen("#{language} #{File.expand_path("~/.ezycli/plugs")}/php/#{plugin_name}.php")
5
+ trap("INT") {
6
+ puts "#{info}Ctrl-C received, cleaning up"
7
+ Process.kill("INT", io.pid)
8
+ }
9
+ io.each do |line|
10
+ if line.chomp.include? "Could not open input file"
11
+ puts "#{error}Failed to run #{language} plug #{plugin_name}"
12
+ else
13
+ puts line.chomp
14
+ end
15
+ end
16
+ trap('INT', 'DEFAULT')
17
+ end
18
+
19
+ def plug_loader(language, plugin_name)
20
+ case
21
+ when (language == "php")
22
+ puts "#{warning}Plugs are limited to output only at this time"
23
+ plug_exec("php", plugin_name)
24
+ else
25
+ puts "#{error}Couldn't find suitable plug language for #{language}"
26
+ end
27
+ end
28
+
29
+ ############ THESE FUNCTIONS MUST EXIST ############
30
+
31
+ def plugin_help
32
+ return ["plug - Executes a plug"]
33
+ end
34
+
35
+ def plugin_commands
36
+ # I know, I know. I'll clean it up later. shhhhh
37
+ return {"plug" => "plug_loader"}
38
+ end
39
+
40
+ def plugin_associations
41
+ # see the above comment.
42
+ return "plug" => ["plug"]
43
+ end
44
+
45
+ ########### THESE FUNCTIONS MUST EXIST ############
@@ -0,0 +1,22 @@
1
+ def reload_plugin(plugin_name)
2
+ unload_plugin plugin_name
3
+ load_plugin plugin_name
4
+ end
5
+
6
+ ############ THESE FUNCTIONS MUST EXIST ############
7
+
8
+ def plugin_help
9
+ return ["reload - Reloads a plugin"]
10
+ end
11
+
12
+ def plugin_commands
13
+ # I know, I know. I'll clean it up later. shhhhh
14
+ return {"reload" => "reload_plugin"}
15
+ end
16
+
17
+ def plugin_associations
18
+ # see the above comment.
19
+ return "reload" => ["reload"]
20
+ end
21
+
22
+ ########### THESE FUNCTIONS MUST EXIST ############
@@ -0,0 +1,7 @@
1
+ def silence_warnings
2
+ original_verbosity = $VERBOSE
3
+ $VERBOSE = nil
4
+ result = yield
5
+ $VERBOSE = original_verbosity
6
+ return result
7
+ end
@@ -0,0 +1,36 @@
1
+ # Yes, the ability to unload plugins is itself a plugin. You may also not unload the plugin unloader. This is a hardcoded dep for the application to run correctly
2
+
3
+ def unload_plugin(plugin_name)
4
+ if REQUIRED_PLUGINS.include? plugin_name
5
+ puts "#{error}Cowardly refusing to unload a core plugin"
6
+ else
7
+ begin
8
+ @plugin_associations["#{plugin_name}"].each do |ext|
9
+ @plugin_commands.delete("#{ext}")
10
+ @plugin_help.reject! {|e| e == ext}
11
+ end
12
+ @plugin_associations.delete("#{plugin_name}")
13
+ puts "#{info}Unloaded plugin #{plugin_name}"
14
+ rescue Exception => e
15
+ puts "#{warning}Failed to unload plugin #{plugin_name}"
16
+ end
17
+ end
18
+ end
19
+
20
+ ############ THESE FUNCTIONS MUST EXIST ############
21
+
22
+ def plugin_help
23
+ return ["unload - Unloads a plugin"]
24
+ end
25
+
26
+ def plugin_commands
27
+ # I know, I know. I'll clean it up later. shhhhh
28
+ return {"unload" => "unload_plugin"}
29
+ end
30
+
31
+ def plugin_associations
32
+ # see the above comment.
33
+ return "unload" => ["unload"]
34
+ end
35
+
36
+ ########### THESE FUNCTIONS MUST EXIST ############
@@ -0,0 +1,21 @@
1
+ puts "#{debug}Setting up listeners..."
2
+ listener = Listen.to(File.expand_path("~/.ezycli/plugins")) do |modified, added, removed|
3
+ puts ""
4
+ added.each do |ext|
5
+ puts "#{info}Found new plugin! #{File.basename(ext, ".rb")}"
6
+ puts "#{debug}Autoloading plugin #{File.basename(ext, ".rb")}"
7
+ load_plugin File.basename(ext, ".rb")
8
+ end
9
+ modified.each do |ext|
10
+ puts "#{info}Detected change in plugin #{File.basename(ext, ".rb")}"
11
+ puts "#{debug}Autoreloading plugin #{File.basename(ext, ".rb")}"
12
+ reload_plugin File.basename(ext, ".rb")
13
+ end
14
+ removed.each do |ext|
15
+ puts "#{info}Detected removal of plugin #{File.basename(ext, ".rb")}"
16
+ puts "#{debug}Autounloading plugin #{File.basename(ext, ".rb")}"
17
+ unload_plugin File.basename(ext, ".rb")
18
+ end
19
+
20
+ end
21
+ listener.start
@@ -0,0 +1,2 @@
1
+ <?php
2
+ echo "Hello, World";
@@ -0,0 +1,11 @@
1
+ #!/bin/env ruby
2
+
3
+ @plugin_counter = 0
4
+ @plugin_array = Array.new
5
+ @plugin_help = Array.new
6
+ @plugin_commands = Hash.new
7
+ @plugin_associations = Hash.new
8
+ # The plugins you are not allowed to unload or reload. To reload these, you need to restart the application.
9
+ REQUIRED_PLUGINS = ["load", "unload", "ezycli"]
10
+ # Freeze the array, no other plugins should be immutable
11
+ REQUIRED_PLUGINS.freeze
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ezycli
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Theo Morra
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: listen
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.5
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 5.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 5.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: readline
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: The ezy way to manage your workspace
56
+ email: theo@theom.nz
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - bin/ezycli
62
+ - lib/cli.rb
63
+ - lib/plugins/ezycli.rb
64
+ - lib/plugins/history.rb
65
+ - lib/plugins/load.rb
66
+ - lib/plugins/plugs.rb
67
+ - lib/plugins/reload.rb
68
+ - lib/plugins/silence.rb
69
+ - lib/plugins/unload.rb
70
+ - lib/plugins/zlisten.rb
71
+ - lib/plugs/php/hello-world.php
72
+ - lib/vars.rb
73
+ homepage: https://github.com/td512/ezycli
74
+ licenses:
75
+ - GPL-3.0+
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.7.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: The ezy way to manage your workspace
97
+ test_files: []