<commit_before>import * as fs from 'fs';
import * as path from 'path';

import * as chalk from 'chalk';

import {
  APIResponse,
  APIResponseSuccess,
  Command,
  CommandLineInputs,
  CommandLineOptions,
  CommandMetadata,
  ICON_SUCCESS_GREEN,
  ICommand,
  ICommandMap,
  TaskChain,
  indent,
  isAPIResponseSuccess,
  prettyPath,
  promisify
} from '@ionic/cli';

const fsWriteFile = promisify<void, string, string>(fs.writeFile);

interface SSHGenerateResponse extends APIResponseSuccess {
  data: {
    key: string,
    pubkey: string
  }
}

function isSSHGenerateResponse(r: APIResponse): r is SSHGenerateResponse {
  return isAPIResponseSuccess(r)
    && typeof r.data['key'] === 'string'
    && typeof r.data['pubkey'] === 'string';
}

@CommandMetadata({
  name: 'generate',
  description: 'Generates a private and public SSH key pair',
  options: [
    {
      name: 'key-path',
      description: 'Destination of private key file',
      default: 'id_rsa'
    },
    {
      name: 'pubkey-path',
      description: 'Destination of public key file',
      default: 'id_rsa.pub'
    }
  ],
  isProjectTask: false
})
export class SSHGenerateCommand extends Command implements ICommand {
  async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
    const keyPath = path.resolve(options['key-path'] ? String(options['key-path']) : 'id_rsa');
    const pubkeyPath = path.resolve(options['pubkey-path'] ? String(options['pubkey-path']) : 'id_rsa.pub');

    const tasks = new TaskChain();<commit_msg>Assume type and cast inside type guard<commit_after>import * as fs from 'fs';
import * as path from 'path';

import * as chalk from 'chalk';

import {
  APIResponse,
  APIResponseSuccess,
  Command,
  CommandLineInputs,
  CommandLineOptions,
  CommandMetadata,
  ICON_SUCCESS_GREEN,
  ICommand,
  TaskChain,
  indent,
  isAPIResponseSuccess,
  prettyPath,
  promisify
} from '@ionic/cli';

const fsWriteFile = promisify<void, string, string>(fs.writeFile);

interface SSHGenerateResponse extends APIResponseSuccess {
  data: {
    key: string,
    pubkey: string
  }
}

function isSSHGenerateResponse(r: APIResponse): r is SSHGenerateResponse {
  const res: SSHGenerateResponse = <SSHGenerateResponse>r;
  return isAPIResponseSuccess(r) && typeof res.data.key === 'string' && typeof res.data.pubkey === 'string';
}

@CommandMetadata({
  name: 'generate',
  description: 'Generates a private and public SSH key pair',
  options: [
    {
      name: 'key-path',
      description: 'Destination of private key file',
      default: 'id_rsa'
    },
    {
      name: 'pubkey-path',
      description: 'Destination of public key file',
      default: 'id_rsa.pub'
    }
  ],
  isProjectTask: false
})
export class SSHGenerateCommand extends Command implements ICommand {
  async run(inputs: CommandLineInputs, options: CommandLineOptions): Promise<void> {
    const keyPath = path.resolve(options['key-path'] ? String(options['key-path']) : 'id_rsa');
    const pubkeyPath = path.resolve(options['pubkey-path'] ? String(options['pubkey-path']) : 'id_rsa.pub');

    const tasks = new TaskChain();
{'fraction_non_alphanumeric': 0.12103746397694524, 'fraction_numerical': 0.0, 'mean_word_length': 4.163636363636364, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '5896537', 'n_tokens_mistral': 978, 'n_tokens_neox': 972, 'n_words': 252}