<commit_before>//
// Copyright (c) Microsoft and contributors.  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 path = require('path');
var fs = require('fs');
var util = require('util');

var profile = require('../../util/profile');
var utils = require('../../util/utils');
var WebsitesClient = require('./websites/websitesclient');

var validation = require('../../util/validation');

var $ = utils.getLocaleString;

exports.init = function (cli) {
  var log = cli.output;
  var site = cli.category('site');
  var siteJobs = site.category('job')
    .description($('Commands to manage your Web Site Web Jobs'));

  siteJobs.command('list [name]')
    .description($('List all the web jobs under a web site'))
    .option('--job-type <job-type>', $('optional. The type of the webjob. Valid value is "triggered" or "continuous". By default return webjobs of all types.'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (name, options, _) {
      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,
        site: {
          name: parsedSiteName.name,
          slot: options.slot ? options.slot : parsedSiteName.slot
        }
      };

      if (options.jobType) {
        validation.isValidEnumValue(options.jobType, [ 'continuous', 'triggered' ]);
      }

      var service = createWebsiteExtensionsClient(context, _);
      var continuousJobs;
      var triggeredJobs;
      var webJobs = [];

      var progress = cli.interaction.progress($('Getting web jobs'));
      try {
        if (!options.jobType || options.jobType === 'continuous') {
          continuousJobs = service.continuousWebJobs.list(_);
        }

        if (!options.jobType || options.jobType === 'triggered') {
          triggeredJobs = service.triggeredWebJobs.list(_);
        }
      } finally {
        progress.end();
      }

      if (continuousJobs) {
        webJobs = webJobs.concat(continuousJobs.continuousWebJobs);
      }

      if (triggeredJobs) {
        webJobs = webJobs.concat(triggeredJobs.triggeredWebJobs);
      }

      cli.interaction.formatOutput(webJobs, function (data) {
        if (data.length > 0) {
          log.table(data, function (row, item) {
            row.cell($('Name'), item.name);
            row.cell($('Type'), item.type);
            row.cell($('Run Command'), item.runCommand);
            row.cell($('Status'), item.status);
          });
        } else {
          log.info($('No jobs exist.'));
        }
      });
    });

  siteJobs.command('show [jobName] [jobType] [name]')
    .usage('[options] <jobName> <jobType> [name]')
    .description($('Show details of a specific webjob'))
    .option('--job-name <job-name>', $('required. The name of the webjob.'))
    .option('--job-type <job-type>', $('required. The type of the webjob. Valid value is "triggered" or "continuous".'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (jobName, jobType, name, options, _) {
      if (jobType) {
        validation.isValidEnumValue(jobType, [ 'continuous', 'triggered' ]);
      } else {
        throw new Error($('--job-type is required'));
      }

      if (!jobName) {
        throw new Error($('--job-name is required'));
      }

      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,
        site: {
          name: parsedSiteName.name,
          slot: options.slot ? options.slot : parsedSiteName.slot
        }
      };

      var service = createWebsiteExtensionsClient(context, _);
      var operation = service[jobType.toLowerCase() + 'WebJobs'];

      var webJob;
      var progress = cli.interaction.progress($('Getting web job'));
      try {
        webJob = operation.get(jobName, _);
      } finally {
        progress.end();
      }

      cli.interaction.logEachData($('Web Job'), webJob.webJob);
    });

  siteJobs.command('delete [jobName] [jobType] [name]')
    .usage('[options] <jobName> <jobType> [name]')
    .description($('Delete a web job'))
    .option('--job-name <job-name>', $('required. The name of the webjob.'))
    .option('--job-type <job-type>', $('required. The type of the webjob. Valid value is "triggered" or "continuous".'))
    .option('-q, --quiet', $('quiet mode, do not ask for delete confirmation'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (jobName, jobType, name, options, _) {
      if (jobType) {
        validation.isValidEnumValue(jobType, [ 'continuous', 'triggered' ]);
      } else {
        throw new Error($('--job-type is required'));
      }

      if (!jobName) {
        throw new Error($('--job-name is required'));
      }

      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,<commit_msg>Fix "azure site job show" command which didn't actually showed the WebJob<commit_after>//
// Copyright (c) Microsoft and contributors.  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 path = require('path');
var fs = require('fs');
var util = require('util');

var profile = require('../../util/profile');
var utils = require('../../util/utils');
var WebsitesClient = require('./websites/websitesclient');

var validation = require('../../util/validation');

var $ = utils.getLocaleString;

exports.init = function (cli) {
  var log = cli.output;
  var site = cli.category('site');
  var siteJobs = site.category('job')
    .description($('Commands to manage your Web Site Web Jobs'));

  siteJobs.command('list [name]')
    .description($('List all the web jobs under a web site'))
    .option('--job-type <job-type>', $('optional. The type of the webjob. Valid value is "triggered" or "continuous". By default return webjobs of all types.'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (name, options, _) {
      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,
        site: {
          name: parsedSiteName.name,
          slot: options.slot ? options.slot : parsedSiteName.slot
        }
      };

      if (options.jobType) {
        validation.isValidEnumValue(options.jobType, [ 'continuous', 'triggered' ]);
      }

      var service = createWebsiteExtensionsClient(context, _);
      var continuousJobs;
      var triggeredJobs;
      var webJobs = [];

      var progress = cli.interaction.progress($('Getting web jobs'));
      try {
        if (!options.jobType || options.jobType === 'continuous') {
          continuousJobs = service.continuousWebJobs.list(_);
        }

        if (!options.jobType || options.jobType === 'triggered') {
          triggeredJobs = service.triggeredWebJobs.list(_);
        }
      } finally {
        progress.end();
      }

      if (continuousJobs) {
        webJobs = webJobs.concat(continuousJobs.continuousWebJobs);
      }

      if (triggeredJobs) {
        webJobs = webJobs.concat(triggeredJobs.triggeredWebJobs);
      }

      cli.interaction.formatOutput(webJobs, function (data) {
        if (data.length > 0) {
          log.table(data, function (row, item) {
            row.cell($('Name'), item.name);
            row.cell($('Type'), item.type);
            row.cell($('Run Command'), item.runCommand);
            row.cell($('Status'), item.status);
          });
        } else {
          log.info($('No jobs exist.'));
        }
      });
    });

  siteJobs.command('show [jobName] [jobType] [name]')
    .usage('[options] <jobName> <jobType> [name]')
    .description($('Show details of a specific webjob'))
    .option('--job-name <job-name>', $('required. The name of the webjob.'))
    .option('--job-type <job-type>', $('required. The type of the webjob. Valid value is "triggered" or "continuous".'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (jobName, jobType, name, options, _) {
      if (jobType) {
        validation.isValidEnumValue(jobType, [ 'continuous', 'triggered' ]);
      } else {
        throw new Error($('--job-type is required'));
      }

      if (!jobName) {
        throw new Error($('--job-name is required'));
      }

      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,
        site: {
          name: parsedSiteName.name,
          slot: options.slot ? options.slot : parsedSiteName.slot
        }
      };

      var service = createWebsiteExtensionsClient(context, _);
      var operation = service[jobType.toLowerCase() + 'WebJobs'];

      var webJob;
      var progress = cli.interaction.progress($('Getting web job'));
      try {
        webJob = operation.get(jobName, _);
      } finally {
        progress.end();
      }

      var jobTypeKey = jobType.toLowerCase() + 'WebJob';
      cli.interaction.logEachData($('Web Job'), webJob[jobTypeKey]);
    });

  siteJobs.command('delete [jobName] [jobType] [name]')
    .usage('[options] <jobName> <jobType> [name]')
    .description($('Delete a web job'))
    .option('--job-name <job-name>', $('required. The name of the webjob.'))
    .option('--job-type <job-type>', $('required. The type of the webjob. Valid value is "triggered" or "continuous".'))
    .option('-q, --quiet', $('quiet mode, do not ask for delete confirmation'))
    .option('--slot <slot>', $('the name of the slot'))
    .option('-s, --subscription <id>', $('the subscription id'))
    .execute(function (jobName, jobType, name, options, _) {
      if (jobType) {
        validation.isValidEnumValue(jobType, [ 'continuous', 'triggered' ]);
      } else {
        throw new Error($('--job-type is required'));
      }

      if (!jobName) {
        throw new Error($('--job-name is required'));
      }

      var parsedSiteName = WebsitesClient.parseSiteName(name);
      var context = {
        subscription: profile.current.getSubscription(options.subscription).id,
{'fraction_non_alphanumeric': 0.15615305067218202, 'fraction_numerical': 0.0008617718028266115, 'mean_word_length': 2.7776692708333335, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '2465045', 'n_tokens_mistral': 3413, 'n_tokens_neox': 3369, 'n_words': 918}