code: func checkReplaceUnitState(unit *schema.Unit) (int, error) {
  	// We replace units only for 'submit', 'load' and
  	// 'start' commands.
  	allowedReplace := map[string][]job.JobState{
  		"submit": []job.JobState{
  			job.JobStateInactive,
  		},
  		"load": []job.JobState{
  			job.JobStateInactive,
  			job.JobStateLoaded,
  		},
  		"start": []job.JobState{
  			job.JobStateInactive,
  			job.JobStateLoaded,
  			job.JobStateLaunched,
  		},
  	}
  
  	if allowedJobs, ok := allowedReplace[currentCommand]; ok {
  		for _, j := range allowedJobs {
  			if job.JobState(unit.DesiredState) == j {
  				return 0, nil
  			}
  		}
  		// Report back to caller that we are not allowed to
  		// cross unit transition states
  		stderr("Warning: can not replace Unit(%s) in state '%s', use the appropriate command", unit.Name, unit.DesiredState)
  	} else {
  		// This function should only be called from 'submit',
  		// 'load' and 'start' upper paths.
  		return 1, fmt.Errorf("error: replacing units is not supported in this context")
  	}
  
  	return 1, nil
  }
docs: // checkReplaceUnitState checks if the unit should be replaced.
  // It takes a Unit object as a parameter.
  // It returns 0 on success and if the unit should be replaced, 1 if the
  // unit should not be replaced; and any error encountered.