epc 1.0.2
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.
- data/CHANGELOG +1 -0
- data/Gemfile +22 -0
- data/Rakefile +67 -0
- data/Rakefile.gem +1 -0
- data/bin/epc +10 -0
- data/lib/epc.rb +126 -0
- data/lib/epc/client/base_client.rb +80 -0
- data/lib/epc/client/http_client.rb +19 -0
- data/lib/epc/client/json_client.rb +48 -0
- data/lib/epc/command/archive_project_command.rb +24 -0
- data/lib/epc/command/archive_solution_command.rb +21 -0
- data/lib/epc/command/attach_library_command.rb +82 -0
- data/lib/epc/command/attach_libraryset_command.rb +32 -0
- data/lib/epc/command/attach_runtime_command.rb +27 -0
- data/lib/epc/command/base_command.rb +451 -0
- data/lib/epc/command/bind_service_command.rb +35 -0
- data/lib/epc/command/build_command.rb +83 -0
- data/lib/epc/command/config/create_config_command.rb +55 -0
- data/lib/epc/command/copy_deployment_command.rb +21 -0
- data/lib/epc/command/create_command.rb +13 -0
- data/lib/epc/command/create_dependency_command.rb +43 -0
- data/lib/epc/command/define_service_command.rb +37 -0
- data/lib/epc/command/delete_config_command.rb +63 -0
- data/lib/epc/command/delete_dependency_command.rb +40 -0
- data/lib/epc/command/delete_group_command.rb +40 -0
- data/lib/epc/command/delete_library_command.rb +30 -0
- data/lib/epc/command/delete_librarylanguage_command.rb +40 -0
- data/lib/epc/command/delete_libraryset_command.rb +40 -0
- data/lib/epc/command/delete_project_command.rb +54 -0
- data/lib/epc/command/delete_role_command.rb +25 -0
- data/lib/epc/command/delete_serviceversion_command.rb +52 -0
- data/lib/epc/command/delete_solution_command.rb +39 -0
- data/lib/epc/command/delete_user_command.rb +31 -0
- data/lib/epc/command/deploy_command.rb +142 -0
- data/lib/epc/command/deployment/create_deployment_command.rb +82 -0
- data/lib/epc/command/detach_library_command.rb +35 -0
- data/lib/epc/command/detach_libraryset_command.rb +8 -0
- data/lib/epc/command/group/create_group_command.rb +21 -0
- data/lib/epc/command/info_command.rb +11 -0
- data/lib/epc/command/library/create_library_command.rb +45 -0
- data/lib/epc/command/librarylanguage/create_librarylanguage_command.rb +24 -0
- data/lib/epc/command/libraryset/create_libraryset_command.rb +54 -0
- data/lib/epc/command/list_approvals_command.rb +27 -0
- data/lib/epc/command/list_attachedlibraries_command.rb +42 -0
- data/lib/epc/command/list_boundservices_command.rb +40 -0
- data/lib/epc/command/list_config_command.rb +60 -0
- data/lib/epc/command/list_dependencies_command.rb +43 -0
- data/lib/epc/command/list_deployments_command.rb +68 -0
- data/lib/epc/command/list_groups_command.rb +19 -0
- data/lib/epc/command/list_libraries_command.rb +19 -0
- data/lib/epc/command/list_librarylanguages_command.rb +19 -0
- data/lib/epc/command/list_librarysets_command.rb +26 -0
- data/lib/epc/command/list_objectroles_command.rb +25 -0
- data/lib/epc/command/list_objecttypes_command.rb +20 -0
- data/lib/epc/command/list_permissiongroups_command.rb +20 -0
- data/lib/epc/command/list_projects_command.rb +36 -0
- data/lib/epc/command/list_projecttypes_command.rb +20 -0
- data/lib/epc/command/list_rolepermissions_command.rb +21 -0
- data/lib/epc/command/list_roles_command.rb +26 -0
- data/lib/epc/command/list_runtimes_command.rb +16 -0
- data/lib/epc/command/list_service_types_command.rb +19 -0
- data/lib/epc/command/list_servicedefinitions_command.rb +19 -0
- data/lib/epc/command/list_serviceversions_command.rb +21 -0
- data/lib/epc/command/list_solutions_command.rb +25 -0
- data/lib/epc/command/list_stages_command.rb +21 -0
- data/lib/epc/command/list_users_command.rb +26 -0
- data/lib/epc/command/list_versions_command.rb +39 -0
- data/lib/epc/command/login_command.rb +32 -0
- data/lib/epc/command/logout_command.rb +20 -0
- data/lib/epc/command/objectrole/create_objectrole_command.rb +19 -0
- data/lib/epc/command/project/create_project_command.rb +78 -0
- data/lib/epc/command/pull_command.rb +209 -0
- data/lib/epc/command/push_command.rb +194 -0
- data/lib/epc/command/refresh_solution_command.rb +71 -0
- data/lib/epc/command/renew_command.rb +19 -0
- data/lib/epc/command/request_passwordchange_command.rb +23 -0
- data/lib/epc/command/role/create_role_command.rb +17 -0
- data/lib/epc/command/serviceversion/create_serviceversion_command.rb +33 -0
- data/lib/epc/command/show_deployment_command.rb +57 -0
- data/lib/epc/command/show_group_command.rb +35 -0
- data/lib/epc/command/show_libraryset_command.rb +54 -0
- data/lib/epc/command/show_project_command.rb +74 -0
- data/lib/epc/command/show_projecttype_command.rb +18 -0
- data/lib/epc/command/show_role_command.rb +46 -0
- data/lib/epc/command/show_solution_command.rb +54 -0
- data/lib/epc/command/show_user_command.rb +42 -0
- data/lib/epc/command/solution/create_solution_command.rb +34 -0
- data/lib/epc/command/solution/list_solutions_command.rb +25 -0
- data/lib/epc/command/solution/update_solution_command.rb +43 -0
- data/lib/epc/command/submit_deployment_command.rb +19 -0
- data/lib/epc/command/target_command.rb +26 -0
- data/lib/epc/command/unarchive_project_command.rb +23 -0
- data/lib/epc/command/unarchive_solution_command.rb +21 -0
- data/lib/epc/command/unbind_service_command.rb +42 -0
- data/lib/epc/command/undefine_service_command.rb +33 -0
- data/lib/epc/command/undeploy_command.rb +106 -0
- data/lib/epc/command/update_config_command.rb +62 -0
- data/lib/epc/command/update_deploymentproject_command.rb +54 -0
- data/lib/epc/command/update_group_command.rb +43 -0
- data/lib/epc/command/update_librarylanguage_command.rb +28 -0
- data/lib/epc/command/update_libraryset_command.rb +80 -0
- data/lib/epc/command/update_project_command.rb +49 -0
- data/lib/epc/command/update_role_command.rb +47 -0
- data/lib/epc/command/update_rolepermissions_command.rb +83 -0
- data/lib/epc/command/update_solution_command.rb +45 -0
- data/lib/epc/command/update_user_command.rb +57 -0
- data/lib/epc/command/user/create_user_command.rb +27 -0
- data/lib/epc/command/vote_deployment_command.rb +29 -0
- data/lib/epc/config.rb +245 -0
- data/lib/epc/error/basic_error.rb +6 -0
- data/lib/epc/error/fatal_error.rb +6 -0
- data/lib/epc/error/input_error.rb +6 -0
- data/lib/epc/error/internal_error.rb +6 -0
- data/lib/epc/help.rb +292 -0
- data/lib/epc/persistent_attributes.rb +18 -0
- data/lib/epc/runner.rb +177 -0
- data/lib/epc/tabular_outputter.rb +161 -0
- data/lib/epc/version.rb +3 -0
- data/lib/fixnum.rb +9 -0
- data/lib/object.rb +13 -0
- data/test/command/archive_project_command_test.rb +41 -0
- data/test/command/archive_solution_command_test.rb +40 -0
- data/test/command/attach_library_command_test.rb +124 -0
- data/test/command/attach_libraryset_command_test.rb +49 -0
- data/test/command/attach_runtime_command_test.rb +44 -0
- data/test/command/base_command_test.rb +276 -0
- data/test/command/bind_service_command_test.rb +46 -0
- data/test/command/build_command_test.rb +103 -0
- data/test/command/copy_deployment_command_test.rb +38 -0
- data/test/command/create_config_command_test.rb +124 -0
- data/test/command/create_dependency_command_test.rb +55 -0
- data/test/command/create_deployment_command_test.rb +136 -0
- data/test/command/create_group_command_test.rb +34 -0
- data/test/command/create_library_command_test.rb +61 -0
- data/test/command/create_librarylanguage_command_test.rb +51 -0
- data/test/command/create_libraryset_command_test.rb +81 -0
- data/test/command/create_objectrole_command_test.rb +37 -0
- data/test/command/create_project_command_test.rb +102 -0
- data/test/command/create_role_command_test.rb +31 -0
- data/test/command/create_serviceversion_command_test.rb +60 -0
- data/test/command/create_solution_command_test.rb +70 -0
- data/test/command/create_user_command_test.rb +54 -0
- data/test/command/define_service_command_test.rb +55 -0
- data/test/command/delete_config_command_test.rb +82 -0
- data/test/command/delete_dependency_command_test.rb +50 -0
- data/test/command/delete_group_command_test.rb +56 -0
- data/test/command/delete_library_command_test.rb +43 -0
- data/test/command/delete_librarylanguage_command_test.rb +55 -0
- data/test/command/delete_libraryset_command_test.rb +55 -0
- data/test/command/delete_project_command_test.rb +76 -0
- data/test/command/delete_role_command_test.rb +41 -0
- data/test/command/delete_serviceversion_command_test.rb +53 -0
- data/test/command/delete_solution_command_test.rb +79 -0
- data/test/command/delete_user_command_test.rb +56 -0
- data/test/command/deploy_command_test.rb +185 -0
- data/test/command/detach_library_command_test.rb +53 -0
- data/test/command/info_command_test.rb +17 -0
- data/test/command/list_approvals_command_test.rb +41 -0
- data/test/command/list_boundservices_command_test.rb +46 -0
- data/test/command/list_config_command_test.rb +72 -0
- data/test/command/list_dependencies_command_test.rb +46 -0
- data/test/command/list_deployments_command_test.rb +112 -0
- data/test/command/list_deploymentstages_command_test.rb +44 -0
- data/test/command/list_libraries_command_test.rb +42 -0
- data/test/command/list_librarylanguages_command_test.rb +34 -0
- data/test/command/list_librarysets_command_test.rb +33 -0
- data/test/command/list_objectroles_command_test.rb +41 -0
- data/test/command/list_objecttypes_command_test.rb +25 -0
- data/test/command/list_permissiongroups_command_test.rb +25 -0
- data/test/command/list_projects_command_test.rb +63 -0
- data/test/command/list_projecttypes_command_test.rb +39 -0
- data/test/command/list_rolepermissions_command_test.rb +39 -0
- data/test/command/list_roles_command_test.rb +46 -0
- data/test/command/list_runtimes_command_test.rb +30 -0
- data/test/command/list_service_types_command_test.rb +44 -0
- data/test/command/list_servicedefinitions_command_test.rb +44 -0
- data/test/command/list_serviceversions_command_test.rb +47 -0
- data/test/command/list_solutions_command_test.rb +48 -0
- data/test/command/list_users_command_test.rb +33 -0
- data/test/command/login_command_test.rb +83 -0
- data/test/command/logout_command_test.rb +30 -0
- data/test/command/pull_command_test.rb +229 -0
- data/test/command/push_command_test.rb +246 -0
- data/test/command/refresh_solution_command_test.rb +35 -0
- data/test/command/renew_command_test.rb +43 -0
- data/test/command/request_passwordchange_command_test.rb +31 -0
- data/test/command/show_group_command_test.rb +50 -0
- data/test/command/show_libraryset_command_test.rb +51 -0
- data/test/command/show_project_command_test.rb +57 -0
- data/test/command/show_projecttype_command_test.rb +46 -0
- data/test/command/show_role_command_test.rb +37 -0
- data/test/command/show_solution_command_test.rb +59 -0
- data/test/command/show_user_command_test.rb +50 -0
- data/test/command/submit_deployment_command_test.rb +37 -0
- data/test/command/target_command_test.rb +58 -0
- data/test/command/unarchive_project_command_test.rb +45 -0
- data/test/command/unarchive_solution_command_test.rb +43 -0
- data/test/command/unbind_service_command_test.rb +48 -0
- data/test/command/undefine_service_command_test.rb +49 -0
- data/test/command/update_config_command_test.rb +74 -0
- data/test/command/update_deploymentproject_command_test.rb +77 -0
- data/test/command/update_group_command_test.rb +69 -0
- data/test/command/update_librarylanguage_command_test.rb +43 -0
- data/test/command/update_libraryset_command_test.rb +113 -0
- data/test/command/update_project_command_test.rb +56 -0
- data/test/command/update_role_command_test.rb +42 -0
- data/test/command/update_rolepermissions_command_test.rb +54 -0
- data/test/command/update_solution_command_test.rb +58 -0
- data/test/command/update_user_command_test.rb +76 -0
- data/test/command/vote_deployment_command_test.rb +33 -0
- data/test/config_test.rb +70 -0
- data/test/successful_test.rb +21 -0
- data/test/test_files/pom.xml +273 -0
- data/test/test_helper.rb +25 -0
- metadata +470 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
module EPC
|
2
|
+
module PersistentAttributes
|
3
|
+
def target_url
|
4
|
+
return @target_url if @target_url
|
5
|
+
@target_url = EPC::Config.target_url
|
6
|
+
end
|
7
|
+
|
8
|
+
def caller_id
|
9
|
+
return @caller_id if @caller_id
|
10
|
+
@caller_id = EPC::Config.caller_id
|
11
|
+
end
|
12
|
+
|
13
|
+
def auth_token
|
14
|
+
return @auth_token if @auth_token
|
15
|
+
@auth_token = EPC::Config.auth_token
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/epc/runner.rb
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
class EPC::Runner
|
4
|
+
include EPC::Help
|
5
|
+
include EPC::PersistentAttributes
|
6
|
+
include EPC::Client
|
7
|
+
include EPC::Error
|
8
|
+
|
9
|
+
def self.run(args)
|
10
|
+
new(args).run
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(args = [])
|
14
|
+
@args = args
|
15
|
+
@options = Hash.new
|
16
|
+
@parent_commands = %w(list delete update show archive unarchive define undefine refresh approve deny bind unbind attach detach submit copy set request)
|
17
|
+
end
|
18
|
+
|
19
|
+
def run
|
20
|
+
begin
|
21
|
+
trap('TERM') { print "\nInterrupted\n"; exit(false)}
|
22
|
+
trap('INT') { print "\nInterrupted\n"; exit(false)}
|
23
|
+
|
24
|
+
parse_options!
|
25
|
+
command_klass = parse_command
|
26
|
+
|
27
|
+
if command_klass
|
28
|
+
begin
|
29
|
+
code = command_klass.go(*@args)
|
30
|
+
exit translate_exit_code(code)
|
31
|
+
rescue InternalError => ex
|
32
|
+
say("An internal error occured. Please contact the AgileMethods support team.")
|
33
|
+
exit 1
|
34
|
+
rescue InputError => ex
|
35
|
+
say(ex.to_s)
|
36
|
+
exit 1
|
37
|
+
rescue FatalError => ex
|
38
|
+
command_name = EPC::Config.underscore(command_klass.class.to_s.split("::").last)
|
39
|
+
# say("USAGE: " + EPC::Help::COMMAND_USAGES[command_name.split("_")[0...-1].join("_").to_sym])
|
40
|
+
say(ex.to_s)
|
41
|
+
exit 1
|
42
|
+
rescue ArgumentError => ex
|
43
|
+
command_name = EPC::Config.underscore(command_klass.class.to_s.split("::").last)
|
44
|
+
say("Wrong number of attributes for #{command_name}")
|
45
|
+
# say("USAGE: " + EPC::Help::COMMAND_USAGES[command_name.split("_")[0...-1].join("_").to_sym])
|
46
|
+
exit 1
|
47
|
+
rescue BaseClient::HTTPException => ex
|
48
|
+
say(ex.to_s)
|
49
|
+
exit 1
|
50
|
+
rescue BaseClient::BadResponse => ex
|
51
|
+
say(ex.to_s)
|
52
|
+
exit 1
|
53
|
+
rescue SocketError => ex
|
54
|
+
say(ex.to_s)
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
rescue OptionParser::InvalidOption => ex
|
60
|
+
rescue OptionParser::AmbiguousOption => ex
|
61
|
+
display_usage
|
62
|
+
end
|
63
|
+
exit 1
|
64
|
+
end
|
65
|
+
|
66
|
+
def translate_exit_code(code)
|
67
|
+
return code if code == 1 || code == 0
|
68
|
+
return (code.to_s =~ /2\d\d/) || 1
|
69
|
+
end
|
70
|
+
|
71
|
+
def parse_options!
|
72
|
+
opts_parser = OptionParser.new do |opts|
|
73
|
+
opts.banner = "\nAvailable options:\n\n"
|
74
|
+
|
75
|
+
opts.on('--email EMAIL') { |email| @options[:email] = email }
|
76
|
+
opts.on('--passwd PASS') { |pass| @options[:password] = pass }
|
77
|
+
opts.on('--up-script FILE') { |file| @options[:up_script] = file}
|
78
|
+
opts.on('--down-script FILE') { |file| @options[:down_script] = file}
|
79
|
+
opts.on('--required') { |required| @options[:required] = true }
|
80
|
+
opts.on('--f FILE') { |file| @options[:file] = file }
|
81
|
+
opts.on('--file FILE') { |file| @options[:file] = file }
|
82
|
+
opts.on('--force') { |force| @options[:force] = true }
|
83
|
+
opts.on('-s NAME') { |name| @options[:solution_name] = name}
|
84
|
+
opts.on('-S NAME') { |name| @options[:stage_name] = name}
|
85
|
+
opts.on('-u NAME') { |name| @options[:user_name] = name}
|
86
|
+
opts.on('--stage NAME') { |name| @options[:stage_name] = name}
|
87
|
+
opts.on('-t SERVICE_TYPE') { |service_type| @options[:service_type] = service_type}
|
88
|
+
opts.on('--type TYPE') { |type| @options[:type] = type}
|
89
|
+
opts.on('--no-required') { |required| @options[:required] = false }
|
90
|
+
opts.on('--nodir') { |nodir| @options[:nodir] = true}
|
91
|
+
opts.on('--value-type TYPE') { |type| @options[:value_type] = type}
|
92
|
+
opts.on('--dep-config NAME') { |name| @options[:dep_config] = name}
|
93
|
+
opts.on('-h', '--help') { display_verbose_usage; exit }
|
94
|
+
opts.on('-d DEPLOYMENT') { |deployment| @options[:deployment_id] = deployment}
|
95
|
+
opts.on('--compile') { |value| @options[:dependency_type] = 1}
|
96
|
+
opts.on('--runtime') { |value| @options[:dependency_type] = 2}
|
97
|
+
opts.on('--depends DEPENDENCY') { |dependency| @options[:dependency] = dependency}
|
98
|
+
opts.on('--group') { |group| @options[:group] = group}
|
99
|
+
opts.on('--uri-name URI_NAME') { |uri_name| @options[:uri_name] = uri_name}
|
100
|
+
opts.on('--no-override') { |val| @options[:no_override] = true }
|
101
|
+
opts.on('--uselocal') { |local| @options[:use_local] = true}
|
102
|
+
opts.on('--replaces DEPLOYMENT') { |deployment| @options[:replaces] = deployment}
|
103
|
+
opts.on('--instances INSTANCES') { |instances| @options[:instances] = instances}
|
104
|
+
opts.on('--uris URIS') { |uris| @options[:uris] = uris}
|
105
|
+
opts.on('--scope SCOPE') { |scope| @options[:scope] = scope}
|
106
|
+
opts.on('--note NOTE') { |note| @options[:note] = note}
|
107
|
+
opts.on('--json') { |json| @options[:json] = true}
|
108
|
+
opts.on('-y') { |skip| @options[:skip_prompts] = true}
|
109
|
+
opts.on('--pom POM') { |pom| @options[:pom] = pom}
|
110
|
+
opts.on('--add-user USER_ID') { |user_id| @options[:add_user] = user_id}
|
111
|
+
opts.on('--remove-user USER_ID') { |user_id| @options[:remove_user] = user_id}
|
112
|
+
opts.on('--language LANGUAGE') { |language| @options[:language] = language}
|
113
|
+
opts.on('--add-library LIB') { |lib| @options[:add_library] = lib}
|
114
|
+
opts.on('--remove-library LIB') { |lib| @options[:remove_library] = lib}
|
115
|
+
opts.on('--token TOKEN') { |token| @options[:token] = token}
|
116
|
+
opts.on('--name NAME') { |name| @options[:name] = name}
|
117
|
+
opts.on('--add-grant grant') { |grant| @options[:add_grant] = grant}
|
118
|
+
opts.on('--remove-grant grant') { |grant| @options[:remove_grant] = grant}
|
119
|
+
opts.on('--add-group group') { |group| @options[:add_group] = group}
|
120
|
+
opts.on('--remove-group group') { |group| @options[:remove_group] = group}
|
121
|
+
opts.on('--nopoll') { |poll| @options[:no_poll] = true}
|
122
|
+
opts.on('--timeout TIMEOUT') { |timeout| @options[:timeout] = timeout}
|
123
|
+
|
124
|
+
opts.on('-p NAME') do |name|
|
125
|
+
if @options[:project_name].nil?
|
126
|
+
@options[:project_name] = name
|
127
|
+
else
|
128
|
+
@options[:project_name] += "|#{name}"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
EPC::Command::CreateConfigCommand::CONFIG_LEVELS.keys.each do |opt|
|
133
|
+
opts.on("--#{opt.to_s.gsub(/[_\ ]/, "-")} opt") {|param| @options[opt.to_sym] = param}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
begin
|
138
|
+
@args = opts_parser.parse!(@args)
|
139
|
+
rescue
|
140
|
+
say("Invalid input.")
|
141
|
+
exit
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def parse_command
|
146
|
+
begin
|
147
|
+
command_name = @args.shift
|
148
|
+
if command_name == "help" || command_name.nil?
|
149
|
+
display_command_usage(*@args)
|
150
|
+
exit 0
|
151
|
+
else
|
152
|
+
if command_name == "approve" || command_name == "deny"
|
153
|
+
@args.shift
|
154
|
+
klass_name = "EPC::Command::VoteDeploymentCommand"
|
155
|
+
@options[:approval] = command_name
|
156
|
+
elsif @parent_commands.include?(command_name)
|
157
|
+
subcommand_name = @args.shift.gsub("-", "")
|
158
|
+
klass_name = "EPC::Command::#{command_name.to_s.capitalize}#{subcommand_name.to_s.capitalize}Command"
|
159
|
+
else
|
160
|
+
klass_name = "EPC::Command::#{command_name.to_s.capitalize}Command"
|
161
|
+
end
|
162
|
+
command_klass = eval(klass_name).new(client, @options)
|
163
|
+
end
|
164
|
+
rescue NameError => ex
|
165
|
+
say("No such command: #{command_name} #{subcommand_name}")
|
166
|
+
display_verbose_usage
|
167
|
+
exit 1
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
private
|
172
|
+
|
173
|
+
def client
|
174
|
+
return @client if @client
|
175
|
+
@client = EPC::Client::JsonClient.new(target_url, caller_id, auth_token)
|
176
|
+
end
|
177
|
+
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module EPC
|
2
|
+
class TabularOutputter
|
3
|
+
|
4
|
+
MAX_WIDTH = 80
|
5
|
+
|
6
|
+
attr_accessor :collection, :fields, :column_widths
|
7
|
+
def initialize(collection, fields)
|
8
|
+
@padding = 2
|
9
|
+
@collection = collection || []
|
10
|
+
parse_fields(fields)
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_fields(fields)
|
15
|
+
if fields.is_a? Array
|
16
|
+
@fields = fields
|
17
|
+
title_row = {}
|
18
|
+
@fields.each do |field|
|
19
|
+
title_row[field] = field.to_s.upcase.gsub("_", " ")
|
20
|
+
end
|
21
|
+
@collection = [title_row] + @collection
|
22
|
+
elsif fields.is_a? Hash
|
23
|
+
fields.each {|k, v| fields[k] = v.to_s.gsub("_", " ")}
|
24
|
+
@fields = fields.keys
|
25
|
+
@col_names = fields
|
26
|
+
@collection = [fields] + @collection
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def compute_col_max_widths
|
31
|
+
@column_widths = {}
|
32
|
+
@fields.each do |field|
|
33
|
+
@column_widths[field] = -1
|
34
|
+
@collection.each do |item|
|
35
|
+
content = get_content(item, field)
|
36
|
+
@column_widths[field] = [content.length, @column_widths[field]].max
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def normalize_col_widths
|
42
|
+
extra = 0
|
43
|
+
while table_length > padded_width + extra
|
44
|
+
max_field, max_length = @column_widths.max{|a, b| a.last <=> b.last}
|
45
|
+
longest = get_longest_word(max_field)
|
46
|
+
available = padded_width - @column_widths.reject{|k, v| k == max_field}.values.reduce(:+)
|
47
|
+
@column_widths[max_field] = [longest, available].max
|
48
|
+
extra = extra + 1
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
def parse
|
54
|
+
compute_col_max_widths
|
55
|
+
normalize_col_widths
|
56
|
+
end
|
57
|
+
|
58
|
+
|
59
|
+
def break_content_for(element, field)
|
60
|
+
content = get_content(element, field)
|
61
|
+
broken_line = []
|
62
|
+
return {field => [content]} if content.length < @column_widths[field]
|
63
|
+
|
64
|
+
while !content.empty?
|
65
|
+
if content.length <= @column_widths[field]
|
66
|
+
broken_line << content.slice!(0..content.length)
|
67
|
+
else
|
68
|
+
line = content[0..@column_widths[field]]
|
69
|
+
if line.include?("\n")
|
70
|
+
position = [line.rindex("\n"), 0].max
|
71
|
+
else
|
72
|
+
position = [line.rindex(/[ ,\.]/) - 1, 0].max
|
73
|
+
end
|
74
|
+
broken_line << content.slice!(0..(position || @column_widths[field])).gsub("\n", "")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
broken_line.delete_if{|a| a == " "}
|
78
|
+
{field => broken_line}
|
79
|
+
end
|
80
|
+
|
81
|
+
def line_for(element)
|
82
|
+
broken_lines = []
|
83
|
+
line = ""
|
84
|
+
@fields.each do |field|
|
85
|
+
broken_lines << break_content_for(element,field)
|
86
|
+
end
|
87
|
+
|
88
|
+
longest_line = broken_lines.collect{|line| line.values.first.size}.max
|
89
|
+
longest_line.times do |index|
|
90
|
+
broken_lines.each do |broken_line|
|
91
|
+
b_line = broken_line.values.first
|
92
|
+
field = broken_line.keys.first
|
93
|
+
|
94
|
+
content = (b_line[index] || (" " * @column_widths[field]))
|
95
|
+
if content =~ /\D/
|
96
|
+
line << content.ljust(@column_widths[field]).ljust(@column_widths[field] + @padding)
|
97
|
+
else
|
98
|
+
line << content.rjust(@column_widths[field]).ljust(@column_widths[field] + @padding)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
line << "\n"
|
102
|
+
end
|
103
|
+
line
|
104
|
+
end
|
105
|
+
|
106
|
+
def print(options = {})
|
107
|
+
parse
|
108
|
+
content = "\n"
|
109
|
+
content << line_for(@collection.delete_at(0))
|
110
|
+
content << ("-" * MAX_WIDTH)
|
111
|
+
content << "\n"
|
112
|
+
@collection.each do |element|
|
113
|
+
content << line_for(element)
|
114
|
+
if !options[:line_separator].nil? && options[:line_separator]
|
115
|
+
content << ("-" * MAX_WIDTH)
|
116
|
+
content << "\n"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
content
|
120
|
+
end
|
121
|
+
|
122
|
+
private
|
123
|
+
|
124
|
+
def get_content(element, field)
|
125
|
+
if element.is_a?(Hash)
|
126
|
+
content = element[field]
|
127
|
+
else
|
128
|
+
content = element.send(field)
|
129
|
+
end
|
130
|
+
return "N/A" if content.nil?
|
131
|
+
return content.to_s
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_longest_word(field)
|
135
|
+
longest = -1
|
136
|
+
@collection.each do |row|
|
137
|
+
content = get_content(row, field)
|
138
|
+
candidate = get_content(row, field).split(split_rule).map(&:length).max
|
139
|
+
longest = [candidate, longest].max
|
140
|
+
end
|
141
|
+
return longest
|
142
|
+
end
|
143
|
+
|
144
|
+
def split_rule
|
145
|
+
return " "
|
146
|
+
end
|
147
|
+
|
148
|
+
def total_padding
|
149
|
+
@fields.size * @padding
|
150
|
+
end
|
151
|
+
|
152
|
+
def table_length
|
153
|
+
@column_widths.values.reduce(:+)
|
154
|
+
end
|
155
|
+
|
156
|
+
def padded_width
|
157
|
+
MAX_WIDTH - total_padding
|
158
|
+
end
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
data/lib/epc/version.rb
ADDED
data/lib/fixnum.rb
ADDED
data/lib/object.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ArchiveProjectCommandTest < Test::Unit::TestCase
|
4
|
+
context "checks" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@command = EPC::Command::ArchiveProjectCommand.new(@mock_client)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "fail if no project id specified" do
|
11
|
+
assert_raise EPC::Error::FatalError do
|
12
|
+
assert_equal 1, @command.execute
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
context "archiving" do
|
17
|
+
setup do
|
18
|
+
@mock_client = mock("Client")
|
19
|
+
@command = EPC::Command::ArchiveProjectCommand.new(@mock_client)
|
20
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
21
|
+
@command.expects(:infer_project_context).returns([1, "FirstProject"])
|
22
|
+
end
|
23
|
+
|
24
|
+
should "fail if status is not 201" do
|
25
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH + "/1", {:archived => true}).
|
26
|
+
returns([404, {:message => "Not Found"}, {}])
|
27
|
+
|
28
|
+
@command.expects(:say).with("Project could not be archived. Request failed with: [Not Found]")
|
29
|
+
assert_equal(@command.execute, 404)
|
30
|
+
end
|
31
|
+
|
32
|
+
should "archive the solution" do
|
33
|
+
@mock_client.expects(:put).with(EPC::Config::PROJECTS_PATH + "/1", {:archived => true}).
|
34
|
+
returns([200, {}, {}])
|
35
|
+
|
36
|
+
@command.expects(:say).with("Project has been archived.")
|
37
|
+
assert_equal(@command.execute, 200)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class ArchiveSolutionCommandTest < Test::Unit::TestCase
|
4
|
+
context "checks" do
|
5
|
+
setup do
|
6
|
+
@mock_client = mock("Client")
|
7
|
+
@command = EPC::Command::ArchiveSolutionCommand.new(@mock_client)
|
8
|
+
end
|
9
|
+
|
10
|
+
should "fail if no solution specified" do
|
11
|
+
assert_raise EPC::Error::FatalError do
|
12
|
+
assert_equal 1, @command.execute
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
context "archiving" do
|
17
|
+
setup do
|
18
|
+
@mock_client = mock("Client")
|
19
|
+
@command = EPC::Command::ArchiveSolutionCommand.new(@mock_client)
|
20
|
+
@command.expects(:infer_solution_context).returns([1, "FirstSolution"])
|
21
|
+
end
|
22
|
+
|
23
|
+
should "fail if status is not 201" do
|
24
|
+
@mock_client.expects(:put).with(EPC::Config::SOLUTIONS_PATH + "/1", {:archived => true, :name => "FirstSolution"}).
|
25
|
+
returns([404, {:message => "Not Found"}, {}])
|
26
|
+
|
27
|
+
@command.expects(:say).with("Solution could not be archived. Request failed with: [Not Found]")
|
28
|
+
assert_equal(@command.execute, 404)
|
29
|
+
end
|
30
|
+
|
31
|
+
should "archive the solution" do
|
32
|
+
@mock_client.expects(:put).with(EPC::Config::SOLUTIONS_PATH + "/1", {:archived => true, :name => "FirstSolution"}).
|
33
|
+
returns([200, {}, {}])
|
34
|
+
|
35
|
+
@command.expects(:say).with("Solution has been archived.")
|
36
|
+
assert_equal(@command.execute, 200)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|