jenkins_shell 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/jsh +136 -0
- data/lib/jenkins_shell.rb +52 -0
- data/lib/jenkins_shell/wish/cd_wish.rb +29 -0
- data/lib/jenkins_shell/wish/cmd_wish.rb +24 -0
- data/lib/jenkins_shell/wish/ls_wish.rb +22 -0
- data/lib/jenkins_shell/wish/pwd_wish.rb +24 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 62684f8fbf197dfe7f84b10e6f1360da5bf35ab0eb27007c8b13a6e284441679
|
4
|
+
data.tar.gz: 6dbcab48ec5d32b1c1a84c50c96f242cc40d7b7197a507f4e693be51e63f3eb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a1ee32220ec85235db0fd0c0e0251d66afc9dcf1b3d6a6882653b0811586c3c4590bef39bc3d1ae0fc2765176a0861f4ba7c236704d82a386de01d2ac861e86c
|
7
|
+
data.tar.gz: d6ef8f8919d86791d3c1ffe7e393fe1e9df2c68629e04f9e41d42ab08788ccee98ad776d1694fb967f928e1d16699de72f087b749333a08ccddad3c16f33d28d
|
data/bin/jsh
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "djinni"
|
4
|
+
require "hilighter"
|
5
|
+
require "io/wait"
|
6
|
+
require "jenkins_shell"
|
7
|
+
require "optparse"
|
8
|
+
|
9
|
+
class JShExit
|
10
|
+
GOOD = 0
|
11
|
+
INVALID_OPTION = 1
|
12
|
+
INVALID_ARGUMENT = 2
|
13
|
+
MISSING_ARGUMENT = 3
|
14
|
+
EXTRA_ARGUMENTS = 4
|
15
|
+
EXCEPTION = 5
|
16
|
+
AMBIGUOUS_ARGUMENT = 6
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(args)
|
20
|
+
options = Hash.new
|
21
|
+
options["port"] = "8080"
|
22
|
+
options["verbose"] = false
|
23
|
+
|
24
|
+
info = "Simulate a cmd prompt using Jenkins script functionality"
|
25
|
+
|
26
|
+
parser = OptionParser.new do |opts|
|
27
|
+
opts.summary_width = 16
|
28
|
+
|
29
|
+
opts.banner = "Usage: #{File.basename($0)} [OPTIONS] <host>"
|
30
|
+
|
31
|
+
opts.on("")
|
32
|
+
|
33
|
+
info.scan(/\S.{0,80}\S(?=\s|$)|\S+/).each do |line|
|
34
|
+
opts.on("#{line}")
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on("", "OPTIONS")
|
38
|
+
|
39
|
+
opts.on("-h", "--help", "Display this help message") do
|
40
|
+
puts opts
|
41
|
+
exit JShExit::GOOD
|
42
|
+
end
|
43
|
+
|
44
|
+
opts.on("--nocolor", "Disable colorized output") do
|
45
|
+
Hilighter.disable
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on(
|
49
|
+
"-p",
|
50
|
+
"--port=PORT",
|
51
|
+
"Use specified port (default: #{options["port"]})"
|
52
|
+
) do |port|
|
53
|
+
options["port"] = port
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on(
|
57
|
+
"-v",
|
58
|
+
"--verbose",
|
59
|
+
"Show backtrace when error occurs"
|
60
|
+
) do
|
61
|
+
options["verbose"] = true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
begin
|
66
|
+
parser.parse!(args)
|
67
|
+
rescue OptionParser::InvalidOption => e
|
68
|
+
puts e.message
|
69
|
+
puts parser
|
70
|
+
exit JShExit::INVALID_OPTION
|
71
|
+
rescue OptionParser::InvalidArgument => e
|
72
|
+
puts e.message
|
73
|
+
puts parser
|
74
|
+
exit JShExit::INVALID_ARGUMENT
|
75
|
+
rescue OptionParser::MissingArgument => e
|
76
|
+
puts e.message
|
77
|
+
puts parser
|
78
|
+
exit JShExit::MISSING_ARGUMENT
|
79
|
+
rescue OptionParser::AmbiguousOption => e
|
80
|
+
puts e.message
|
81
|
+
puts parser
|
82
|
+
exit JShExit::AMBIGUOUS_ARGUMENT
|
83
|
+
end
|
84
|
+
|
85
|
+
if (args.empty?)
|
86
|
+
puts parser
|
87
|
+
exit JShExit::MISSING_ARGUMENT
|
88
|
+
elsif (args.length == 1)
|
89
|
+
options["host"] = args[0]
|
90
|
+
else
|
91
|
+
puts parser
|
92
|
+
exit JShExit::EXTRA_ARGUMENTS
|
93
|
+
end
|
94
|
+
|
95
|
+
return options
|
96
|
+
end
|
97
|
+
|
98
|
+
options = parse(ARGV)
|
99
|
+
|
100
|
+
begin
|
101
|
+
jsh = JenkinsShell.new(options["host"], options["port"])
|
102
|
+
|
103
|
+
djinni = Djinni.new
|
104
|
+
djinni.fallback = "cmd"
|
105
|
+
djinni.load_wishes(
|
106
|
+
"#{File.dirname(__FILE__)}/../lib/jenkins_shell/wish"
|
107
|
+
)
|
108
|
+
djinni.prompt({"jsh" => jsh}, "#{jsh.pwd}> ".light_white)
|
109
|
+
rescue SystemExit
|
110
|
+
# Quite from djinni
|
111
|
+
# Exit gracefully
|
112
|
+
rescue Interrupt
|
113
|
+
# ^C
|
114
|
+
# Exit gracefully
|
115
|
+
rescue Errno::EPIPE
|
116
|
+
# Do nothing. This can happen if piping to another program such as
|
117
|
+
# less. Usually if less is closed before we're done with STDOUT.
|
118
|
+
rescue Exception => e
|
119
|
+
$stderr.puts "Oops! Looks like an error has occured! If the " \
|
120
|
+
"error persists, file a bug at:".wrap
|
121
|
+
$stderr.puts
|
122
|
+
$stderr.puts " https://gitlab.com/mjwhitta/todo/issues"
|
123
|
+
$stderr.puts
|
124
|
+
$stderr.puts "Maybe the message below will help. If not, you " \
|
125
|
+
"can use the --verbose flag to get a backtrace.".wrap
|
126
|
+
$stderr.puts
|
127
|
+
|
128
|
+
$stderr.puts e.message.white.on_red
|
129
|
+
if (options["verbose"])
|
130
|
+
e.backtrace.each do |line|
|
131
|
+
$stderr.puts line.light_yellow
|
132
|
+
end
|
133
|
+
end
|
134
|
+
exit JShExit::EXCEPTION
|
135
|
+
end
|
136
|
+
exit JShExit::GOOD
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "rexml/document"
|
3
|
+
require "uri"
|
4
|
+
|
5
|
+
class JenkinsShell
|
6
|
+
attr_reader :cwd
|
7
|
+
attr_reader :host
|
8
|
+
attr_reader :port
|
9
|
+
|
10
|
+
def cd(dir = nil)
|
11
|
+
return true if (dir.nil? || dir.empty?)
|
12
|
+
|
13
|
+
new_cwd = pwd("#{@int_cwd}/#{dir}")
|
14
|
+
|
15
|
+
return false if (new_cwd.empty? || (new_cwd == @cwd))
|
16
|
+
|
17
|
+
@cwd = new_cwd
|
18
|
+
@int_cwd = "#{@int_cwd}/#{dir}".gsub(%r{[^/]+/\.\.}, "")
|
19
|
+
|
20
|
+
return true
|
21
|
+
end
|
22
|
+
|
23
|
+
def command(cmd, dir = @int_cwd)
|
24
|
+
# Create and encode Groovy script
|
25
|
+
fix = dir.gsub(/\\/, "\\\\\\")
|
26
|
+
gs = "println(\"cmd /c cd #{fix} && #{cmd}\".execute().text)"
|
27
|
+
enc = URI::encode(URI::encode(gs), "&()/").gsub("%20", "+")
|
28
|
+
|
29
|
+
# Establish connection and send script
|
30
|
+
http = Net::HTTP.new(@host, @port)
|
31
|
+
xml = REXML::Document.new(
|
32
|
+
http.post("/script", "script=#{enc}").body
|
33
|
+
)
|
34
|
+
|
35
|
+
# Parse response and return script output
|
36
|
+
return xml.get_elements("html/body/div/div/pre")[1].text
|
37
|
+
end
|
38
|
+
|
39
|
+
def initialize(host, port = 8080)
|
40
|
+
@int_cwd = "."
|
41
|
+
@host = host.gsub(/^https?:\/\/|(:[0-9]+)?\/.+/, "")
|
42
|
+
@port = port
|
43
|
+
@cwd = pwd
|
44
|
+
end
|
45
|
+
|
46
|
+
def pwd(dir = @int_cwd)
|
47
|
+
command("dir", dir).match(/^\s+Directory of (.+)/) do |m|
|
48
|
+
return m[1]
|
49
|
+
end
|
50
|
+
return ""
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require "djinni"
|
2
|
+
require "hilighter"
|
3
|
+
|
4
|
+
class CDWish < Djinni::Wish
|
5
|
+
def aliases
|
6
|
+
return ["cd"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def description
|
10
|
+
return "Change to new directory"
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute(args, djinni_env = Hash.new)
|
14
|
+
usage if (args.empty?)
|
15
|
+
|
16
|
+
jsh = djinni_env["jsh"]
|
17
|
+
if (!jsh.cd(args))
|
18
|
+
puts "Directory not found"
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
|
23
|
+
end
|
24
|
+
|
25
|
+
def usage
|
26
|
+
puts "#{aliases.join(", ")} <directory>"
|
27
|
+
puts " #{description}."
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "djinni"
|
2
|
+
|
3
|
+
class CmdWish < Djinni::Wish
|
4
|
+
def aliases
|
5
|
+
return ["cmd"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
return "Run command as if in cmd (default behavior)"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(args, djinni_env = Hash.new)
|
13
|
+
usage if (args.empty?)
|
14
|
+
|
15
|
+
jsh = djinni_env["jsh"]
|
16
|
+
puts jsh.command(args)
|
17
|
+
djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
|
18
|
+
end
|
19
|
+
|
20
|
+
def usage
|
21
|
+
puts "#{aliases.join(", ")} <commands>"
|
22
|
+
puts " #{description}."
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "djinni"
|
2
|
+
|
3
|
+
class LSWish < Djinni::Wish
|
4
|
+
def aliases
|
5
|
+
return ["ls", "dir"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
return "List directory contents"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(args, djinni_env = Hash.new)
|
13
|
+
jsh = djinni_env["jsh"]
|
14
|
+
puts jsh.command("dir #{args}")
|
15
|
+
djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
|
16
|
+
end
|
17
|
+
|
18
|
+
def usage
|
19
|
+
puts "#{aliases.join(", ")} [directory]"
|
20
|
+
puts " #{description}."
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "djinni"
|
2
|
+
|
3
|
+
class PwdWish < Djinni::Wish
|
4
|
+
def aliases
|
5
|
+
return ["pwd"]
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
return "Show path of current path"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute(args, djinni_env = Hash.new)
|
13
|
+
usage if (!args.empty?)
|
14
|
+
|
15
|
+
jsh = djinni_env["jsh"]
|
16
|
+
puts jsh.cwd if (args.empty?)
|
17
|
+
djinni_env["djinni_prompt"] = "#{jsh.cwd}> ".light_white
|
18
|
+
end
|
19
|
+
|
20
|
+
def usage
|
21
|
+
puts aliases.join(", ")
|
22
|
+
puts " #{description}."
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jenkins_shell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Miles Whittaker
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '12.3'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 12.3.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '12.3'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 12.3.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: djinni
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.2'
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.2.0
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '2.2'
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 2.2.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: hilighter
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.2'
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.2.1
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.2'
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.2.1
|
73
|
+
description: This gem will use the scripting functionality of Jenkins to simulate
|
74
|
+
a Windows cmd prompt.
|
75
|
+
email: mjwhitta@gmail.com
|
76
|
+
executables:
|
77
|
+
- jsh
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- bin/jsh
|
82
|
+
- lib/jenkins_shell.rb
|
83
|
+
- lib/jenkins_shell/wish/cd_wish.rb
|
84
|
+
- lib/jenkins_shell/wish/cmd_wish.rb
|
85
|
+
- lib/jenkins_shell/wish/ls_wish.rb
|
86
|
+
- lib/jenkins_shell/wish/pwd_wish.rb
|
87
|
+
homepage: https://mjwhitta.github.io/jenkins_shell
|
88
|
+
licenses:
|
89
|
+
- GPL-3.0
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.7.6
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Simulate a cmd prompt using Jenkins.
|
111
|
+
test_files: []
|