Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rough concept: detect pipe when calling job:show command #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions lib/td/command/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ module Command
/\A[\+]?2\z/ => 2,
}

is_tty = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@is_tty ?

or how define is_tty? method?

def on_tty?
  STDOUT.tty?
end

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea. probably to define method is good way for this.


def job_list(op)
page = 0
skip = 0
Expand Down Expand Up @@ -88,6 +90,7 @@ def job_show(op)
format = 'tsv'
render_opts = {}
exclude = false
@is_tty = STDOUT.tty?

op.on('-v', '--verbose', 'show logs', TrueClass) {|b|
verbose = b
Expand Down Expand Up @@ -117,40 +120,40 @@ def job_show(op)

job = client.job(job_id)

puts "Organization : #{job.org_name}"
puts "JobID : #{job.job_id}"
puts_when_tty "Organization : #{job.org_name}"
puts_when_tty "JobID : #{job.job_id}"
#puts "URL : #{job.url}"
puts "Status : #{job.status}"
puts "Type : #{job.type}"
puts "Priority : #{job_priority_name_of(job.priority)}"
puts "Retry limit : #{job.retry_limit}"
puts "Result : #{job.result_url}"
puts "Database : #{job.db_name}"
puts "Query : #{job.query}"
puts_when_tty "Status : #{job.status}"
puts_when_tty "Type : #{job.type}"
puts_when_tty "Priority : #{job_priority_name_of(job.priority)}"
puts_when_tty "Retry limit : #{job.retry_limit}"
puts_when_tty "Result : #{job.result_url}"
puts_when_tty "Database : #{job.db_name}"
puts_when_tty "Query : #{job.query}"

if wait && !job.finished?
wait_job(job)
if job.success? && [:hive, :pig, :impala].include?(job.type) && !exclude
puts "Result :"
puts_when_tty "Result :"
show_result(job, output, format, render_opts)
end

else
if job.success? && [:hive, :pig, :impala].include?(job.type) && !exclude
puts "Result :"
puts_when_tty "Result :"
show_result(job, output, format, render_opts)
end

if verbose
puts ""
puts "cmdout:"
puts_when_tty ""
puts_when_tty "cmdout:"
job.debug['cmdout'].to_s.split("\n").each {|line|
puts " "+line
puts_when_tty " "+line
}
puts ""
puts "stderr:"
puts_when_tty ""
puts_when_tty "stderr:"
job.debug['stderr'].to_s.split("\n").each {|line|
puts " "+line
puts_when_tty " "+line
}
end
end
Expand Down Expand Up @@ -214,7 +217,9 @@ def wait_job(job)
end

def show_result(job, output, format, render_opts={})
if output
if !@is_tty
write_result(job, "/dev/stdout", format)
elsif output
write_result(job, output, format)
puts "written to #{output} in #{format} format"
else
Expand Down Expand Up @@ -322,6 +327,12 @@ def job_priority_id_of(name)
}
return nil
end

def puts_when_tty(message)
if @is_tty
puts message
end
end
end
end