message: cleanup: separate out publish message building logic
diff: @@ -31,33 +31,9 @@ pub fn publish(
  ) -> Result<(), failure::Error> {
  validate_target_required_fields_present(target)?;
  - let deploy = |target: &Target| match deploy::worker(&user, &deployments) {
  - Ok(deploy::DeployResults { urls, schedules }) => {
  - let result_msg = match (urls.as_slice(), schedules.as_slice()) {
  - ([], []) => "Successfully published your script".to_owned(),
  - ([], schedules) => format!(
  - "Successfully published your script with this schedule\n {}",
  - schedules.join("\n ")
  - ),
  - (urls, []) => format!(
  - "Successfully published your script to\n {}",
  - urls.join("\n ")
  - ),
  - (urls, schedules) => format!(
  - "Successfully published your script to\n {}\nwith this schedule\n {}",
  - urls.join("\n "),
  - schedules.join("\n ")
  - ),
  - };
  - StdErr::success(&result_msg);
  - if out == Output::Json {
  - StdOut::as_json(&PublishOutput {
  - success: true,
  - name: target.name.clone(),
  - urls,
  - schedules,
  - });
  - }
  + let deploy = |target: &Target| match deploy::deploy(&user, &deployments) {
  + Ok(results) => {
  + build_output_message(results, target.name.clone(), out);
  Ok(())
  }
  Err(e) => Err(e),
  @@ -153,6 +129,28 @@ pub fn publish(
  Ok(())
  }
  +fn build_output_message(deploy_results: deploy::DeployResults, target_name: String, out: Output) {
  + let deploy::DeployResults { urls, schedules } = deploy_results;
  +
  + let mut msg = "Successfully published your script ".to_owned();
  + if !urls.is_empty() {
  + msg.push_str(&format!("to\n {}\n", urls.join("\n ")));
  + }
  + if !schedules.is_empty() {
  + msg.push_str(&format!("with this schedule\n {}\n", schedules.join("\n ")));
  + }
  +
  + StdErr::success(&msg);
  + if out == Output::Json {
  + StdOut::as_json(&PublishOutput {
  + success: true,
  + name: target_name,
  + urls,
  + schedules,
  + });
  + }
  +}
  +
  // We don't want folks setting their bucket to the top level directory,
  // which is where wrangler commands are always called from.
  pub fn validate_bucket_location(bucket: &PathBuf) -> Result<(), failure::Error> {
  