<commit_before># Copyright (c) 2009-2012 VMware, Inc.
require 'cli/job_state'
require 'cli/vm_state'

module Bosh::Cli::Command
  class JobManagement < Base
    FORCE = 'Proceed even when there are other manifest changes'

    # bosh start
    usage 'start'
    desc 'Start job/instance'
    option '--force', FORCE
    def start_job(job, index = nil)
      change_job_state(:start, job, index)
    end

    # bosh stop
    usage 'stop'
    desc 'Stop job/instance'
    option '--soft', 'Stop process only'
    option '--hard', 'Power off VM'
    option '--force', FORCE
    def stop_job(job, index = nil)
      if hard?
        change_job_state(:detach, job, index)
      else
        change_job_state(:stop, job, index)
      end
    end

    # bosh restart
    usage 'restart'
    desc 'Restart job/instance (soft stop + start)'
    option '--force', FORCE
    def restart_job(job, index = nil)
      change_job_state(:restart, job, index)
    end

    # bosh recreate
    usage 'recreate'
    desc 'Recreate job/instance (hard stop + start)'
    option '--force', FORCE
    def recreate_job(job, index = nil)
      change_job_state(:recreate, job, index)
    end

    private

    def change_job_state(state, job, index = nil)
      check_arguments(state, job)
      index = valid_index_for(job, index)
      vm_state = VmState.new(self, force?)
      JobState.new(self, vm_state).change(state, job, index)
    end

    def hard?
      options[:hard]
    end

    def soft?
      options[:soft]
    end

    def force?
      options[:force]
    end

    def check_arguments(operation, job)
      auth_required
      job_must_exist_in_deployment(job)

      if hard? && soft?
        err('Cannot handle both --hard and --soft options, please choose one')
      end

      if !hard_and_soft_options_allowed?(operation) && (hard? || soft?)
        err("--hard and --soft options only make sense for `stop' operation")
      end
    end

    def hard_and_soft_options_allowed?(operation)
      operation == :stop || operation == :detach
    end

    def check_if_manifest_changed(manifest)
      return if force?

      other_changes_present = inspect_deployment_changes(
          manifest, :show_empty_changeset => false)

      if other_changes_present
        err('Cannot perform job management when other deployment changes ' +
                "are present. Please use `--force' to override.")
      end
    end
  end
end<commit_msg>Remove unused method<commit_after># Copyright (c) 2009-2012 VMware, Inc.
require 'cli/job_state'
require 'cli/vm_state'

module Bosh::Cli::Command
  class JobManagement < Base
    FORCE = 'Proceed even when there are other manifest changes'

    # bosh start
    usage 'start'
    desc 'Start job/instance'
    option '--force', FORCE
    def start_job(job, index = nil)
      change_job_state(:start, job, index)
    end

    # bosh stop
    usage 'stop'
    desc 'Stop job/instance'
    option '--soft', 'Stop process only'
    option '--hard', 'Power off VM'
    option '--force', FORCE
    def stop_job(job, index = nil)
      if hard?
        change_job_state(:detach, job, index)
      else
        change_job_state(:stop, job, index)
      end
    end

    # bosh restart
    usage 'restart'
    desc 'Restart job/instance (soft stop + start)'
    option '--force', FORCE
    def restart_job(job, index = nil)
      change_job_state(:restart, job, index)
    end

    # bosh recreate
    usage 'recreate'
    desc 'Recreate job/instance (hard stop + start)'
    option '--force', FORCE
    def recreate_job(job, index = nil)
      change_job_state(:recreate, job, index)
    end

    private

    def change_job_state(state, job, index = nil)
      check_arguments(state, job)
      index = valid_index_for(job, index)
      vm_state = VmState.new(self, force?)
      JobState.new(self, vm_state).change(state, job, index)
    end

    def hard?
      options[:hard]
    end

    def soft?
      options[:soft]
    end

    def force?
      options[:force]
    end

    def check_arguments(operation, job)
      auth_required
      job_must_exist_in_deployment(job)

      if hard? && soft?
        err('Cannot handle both --hard and --soft options, please choose one')
      end

      if !hard_and_soft_options_allowed?(operation) && (hard? || soft?)
        err("--hard and --soft options only make sense for `stop' operation")
      end
    end

    def hard_and_soft_options_allowed?(operation)
      operation == :stop || operation == :detach
    end
  end
end
{'fraction_non_alphanumeric': 0.1021946353358457, 'fraction_numerical': 0.0035468853912657946, 'mean_word_length': 2.583796664019063, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4321935', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1389, 'n_words': 418}