lib/gooddata/cli/commands/process_cmd.rb in gooddata-0.6.10 vs lib/gooddata/cli/commands/process_cmd.rb in gooddata-0.6.11
- old
+ new
@@ -3,10 +3,20 @@
require 'pp'
require_relative '../shared'
require_relative '../../commands/process'
+def read_params_file(filename)
+ # read params from a file
+ # if filename nil, return empty hash
+ if filename
+ JSON.parse(IO.read(filename))
+ else
+ {}
+ end
+end
+
GoodData::CLI.module_eval do
desc 'Work with deployed processes'
arg_name 'Describe arguments to list here'
command :process do |c|
@@ -29,10 +39,22 @@
c.desc 'Specify executable of the process'
c.default_value nil
c.flag :executable
+ c.desc 'Specify parameters file to execute the process with'
+ c.default_value nil
+ c.flag :params
+
+ c.desc 'Specify hidden paremeters to execute the process with'
+ c.default_value nil
+ c.flag :hidden_params
+
+ c.desc 'Specify cron expression for the schedule'
+ c.default_value nil
+ c.flag :cron
+
c.desc "Lists all user's processes deployed on the plaform"
c.command :list do |list|
list.action do |global_options, options, args|
opts = options.merge(global_options)
client = GoodData.connect(opts)
@@ -44,20 +66,20 @@
end
end
c.desc 'Gives you some basic info about the process'
c.command :show do |get|
- get.action do |global_options, options, args|
+ get.action do |global_options, options, _args|
opts = options.merge(global_options)
client = GoodData.connect(opts)
pp GoodData::Command::Process.get(opts.merge(client: client)).raw_data
end
end
c.desc 'Deploys provided directory to the server'
c.command :deploy do |deploy|
- deploy.action do |global_options, options, args|
+ deploy.action do |global_options, options, _args|
opts = options.merge(global_options)
dir = opts[:dir]
name = opts[:name]
fail 'You have to provide a directory or a file to deploy. Use --dir param' if dir.nil? || dir.empty?
fail 'You have to provide a name of the deployed process. Use --name param' if name.nil? || name.empty?
@@ -67,30 +89,55 @@
end
end
c.desc 'Delete specific process'
c.command :delete do |deploy|
- deploy.action do |global_options, options, args|
+ deploy.action do |global_options, options, _args|
opts = options.merge(global_options)
process_id = opts[:process_id]
fail 'You have to provide a process id. Use --process_id param' if process_id.nil? || process_id.empty?
client = GoodData.connect(opts)
GoodData::Command::Process.delete(process_id, opts.merge(client: client))
puts "Process #{process_id} was deleted"
end
end
c.desc 'Execute specific deployed process'
- # TODO: Add params. HOW?
c.command :execute do |deploy|
- deploy.action do |global_options, options, args|
+ deploy.action do |global_options, options, _args|
opts = options.merge(global_options)
process_id = opts[:process_id]
executable = opts[:executable]
+
fail 'You have to provide a process id. Use --process_id param' if process_id.nil? || process_id.empty?
fail 'You have to provide an executable for the process. Use --executable param' if executable.nil? || executable.empty?
- GoodData.connect(opts)
- pp GoodData::Command::Process.execute_process(process_id, executable, opts)
+ client = GoodData.connect(options)
+ project = client.projects(options[:project_id])
+ process = project.processes(options[:process_id])
+ params = read_params_file(options[:params])
+ hidden_params = read_params_file(options[:hidden_params])
+ process.execute(options[:executable], params: params, hidden_params: hidden_params)
+ end
+ end
+
+ c.desc 'Schedule specific deployed process'
+ c.command :schedule do |schedule|
+ schedule.action do |global_options, command_options, _|
+ options = command_options.merge(global_options)
+ process_id = options[:process_id]
+ executable = options[:executable]
+ cron = options[:cron]
+
+ fail 'You have to provide a process id. Use --process_id param' if process_id.nil? || process_id.empty?
+ fail 'You have to provide an executable for the process. Use --executable param' if executable.nil? || executable.empty?
+ fail 'You have to provide a cron expression for the schedule. Use --cron param' if cron.nil? || cron.empty?
+
+ client = GoodData.connect(options)
+ project = client.projects(options[:project_id])
+ process = project.processes(options[:process_id])
+ params = read_params_file(options[:params])
+ hidden_params = read_params_file(options[:hidden_params])
+ process.create_schedule(cron, options[:executable], params: params, hidden_params: hidden_params)
end
end
end
end