<commit_before>/**
* Copyright (c) Microsoft.  All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var utils = require('../util/utils');
var interaction = require('../util/interaction');

exports.init = function (cli) {

  var log = cli.output;
  var site = cli.category('site');
  var siteScale = site.category('scale')
    .description('Commands to manage your Web Site scaling');

  siteScale.command('mode [name] <siteMode>')
    .description('Sets the web site mode')
    .usage('[name] <mode>')
    .option('--mode <siteMode>', 'The mode of the site (available are: free, shared and reserved)')
    .option('-s, --subscription <id>', 'use the subscription id')
    .execute(function (name, siteMode, options, _) {
      var params = utils.normalizeParameters({
        siteMode: [siteMode, options.siteMode]
      });

      if (params.err) { throw params.err; }

      siteMode = interaction.promptPasswordIfNotGiven(cli, 'Site mode', params.values.siteMode, _);

      var context = {
        subscription: cli.category('account').lookupSubscriptionId(options.subscription),
        site: {
          name: name
        }
      };

      site.lookupSiteNameAndWebSpace(context, _);
      var siteConfigurations = {};

      var service = createWebsiteManagementService(context.subscription);

      switch(siteMode.toLowerCase()) {
      case 'free':
        siteConfigurations.ComputeMode = 'Shared';
        siteConfigurations.SiteMode = 'Limited';
        break;
      case 'shared':
        siteConfigurations.ComputeMode = 'Shared';
        siteConfigurations.SiteMode = 'Basic';
        break;
      case 'reserved':
        try {
          service.getServerFarm(context.site.webspace, 'DefaultServerFarm', _);
        } catch (err) {
          if (err && err.code === 'NotFound') {
            service.createServerFarm(context.site.webspace,
              'DefaultServerFarm',
              1,
              'Small',
              _);
          } else {
            throw err;
          }
        }

        siteConfigurations.ComputeMode = 'Dedicated';
        siteConfigurations.ServerFarm = 'DefaultServerFarm';
        siteConfigurations.SiteMode = 'Basic';
        break;
      default:
        throw new Error('Valid modes are: \'free\', \'shared\' and \'reserved\'');
      }
<commit_msg>#526: When calling Azure Site Scale without mode, the error mentions 'siteMode'<commit_after>/**
* Copyright (c) Microsoft.  All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

var utils = require('../util/utils');
var interaction = require('../util/interaction');

exports.init = function (cli) {

  var log = cli.output;
  var site = cli.category('site');
  var siteScale = site.category('scale')
    .description('Commands to manage your Web Site scaling');

  siteScale.command('mode [name] <mode>')
    .description('Sets the web site mode')
    .usage('[name] <mode>')
    .option('--mode <mode>', 'The mode of the site (available are: free, shared and reserved)')
    .option('-s, --subscription <id>', 'use the subscription id')
    .execute(function (name, mode, options, _) {
      var params = utils.normalizeParameters({
        mode: [mode, options.mode]
      });

      if (params.err) { throw params.err; }

      mode = interaction.promptPasswordIfNotGiven(cli, 'mode', params.values.mode, _);

      var context = {
        subscription: cli.category('account').lookupSubscriptionId(options.subscription),
        site: {
          name: name
        }
      };

      site.lookupSiteNameAndWebSpace(context, _);
      var siteConfigurations = {};

      var service = createWebsiteManagementService(context.subscription);

      switch(mode.toLowerCase()) {
      case 'free':
        siteConfigurations.ComputeMode = 'Shared';
        siteConfigurations.SiteMode = 'Limited';
        break;
      case 'shared':
        siteConfigurations.ComputeMode = 'Shared';
        siteConfigurations.SiteMode = 'Basic';
        break;
      case 'reserved':
        try {
          service.getServerFarm(context.site.webspace, 'DefaultServerFarm', _);
        } catch (err) {
          if (err && err.code === 'NotFound') {
            service.createServerFarm(context.site.webspace,
              'DefaultServerFarm',
              1,
              'Small',
              _);
          } else {
            throw err;
          }
        }

        siteConfigurations.ComputeMode = 'Dedicated';
        siteConfigurations.ServerFarm = 'DefaultServerFarm';
        siteConfigurations.SiteMode = 'Basic';
        break;
      default:
        throw new Error('Valid modes are: \'free\', \'shared\' and \'reserved\'');
      }

{'fraction_non_alphanumeric': 0.12035242290748899, 'fraction_numerical': 0.0022907488986784142, 'mean_word_length': 2.6929082628497074, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '786436', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1537, 'n_words': 454}