All files cli.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 0/0
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227    1x                       1x 1x 1x 1x 1x   1x 1x   1x               1x               1x                                                                                                                                                                                                                                                                                                                                                                                      
 
 
import {
  Arg,
  collect,
  Command,
  Flag,
  Help,
  KWArg,
  Program,
  RequireAll,
  RequireAny,
  Required,
} from 'jargs';
import env from './env';
import init from './init';
import program from './program';
import run from './run';
import start from './start';
 
const NAME = 'watfish';
const PROGRAM = 'wtf';
 
const ENVIRONMENT = KWArg(
  'env',
  {
    alias: 'e',
    description: 'Environment to use or configure',
  }
);
 
const COMMAND = Arg(
  'command',
  {
    description: 'Arbitrary command to run in the environment',
    multi: true,
  }
);
 
collect(
  Help(
    'help',
    {
      alias: 'h',
      description: 'Display help and usage info',
    },
    Program(
      NAME,
      {
        description:
          'Simple development platform with process management & router',
        usage: `${PROGRAM} command [<sub-command>] [options]`,
        examples: [
          `${PROGRAM} init`,
          `${PROGRAM} env set KEY value`,
          `${PROGRAM} start`,
          `${PROGRAM} start --env production`,
          `${PROGRAM} run manage.py migrate`,
        ],
        callback: program,
      },
      RequireAny(
        Command(
          'init',
          {
            alias: 'i',
            description: 'Generate project config (in ~/wtf.json)',
            usage: `${PROGRAM} init`,
            examples: [
              `${PROGRAM} init`,
            ],
            callback: init,
          }
        ),
        Command(
          'start',
          {
            alias: 's',
            description: 'Start project processes',
            usage: `${PROGRAM} start [options]`,
            examples: [
              `${PROGRAM} start`,
              `${PROGRAM} start watcher`,
              `${PROGRAM} start --env production`,
            ],
            callback: start,
          },
          Arg(
            'processes',
            {
              multi: true,
              description: 'Process to start',
            }
          ),
          KWArg(
            'exclude',
            {
              alias: 'x',
              multi: true,
              description: 'Process to exclude from starting',
            }
          ),
          ENVIRONMENT,
          Flag(
            'time',
            {
              alias: 't',
              description: 'Display time in logs',
            }
          )
        ),
        Command(
          'env',
          {
            alias: 'e',
            description: 'Change local project environment variables',
            usage: `${PROGRAM} env [options]`,
            examples: [
              `${PROGRAM} env`,
              `${PROGRAM} env set key value`,
              `${PROGRAM} env get key`,
              `${PROGRAM} env del key`,
              `${PROGRAM} env set key value --env production`,
            ],
            callback: env,
          },
          ENVIRONMENT,
          Command(
            'set',
            {
              alias: 's',
              description: 'Set config value',
              usage: `${PROGRAM} config set [options]`,
              examples: [
                `${PROGRAM} env set key value`,
                `${PROGRAM} env set key value --env production`,
              ],
            },
            ENVIRONMENT,
            RequireAll(
              Arg(
                'key',
                {
                  description: 'Key to set in config',
                }
              ),
              Arg(
                'value',
                {
                  description: 'Value to set in config',
                }
              )
            )
          ),
          Command(
            'get',
            {
              alias: 'g',
              description: 'Get config value',
              usage: `${PROGRAM} config get [options]`,
              examples: [
                `${PROGRAM} env get key`,
                `${PROGRAM} env set key --env production`,
              ],
            },
            ENVIRONMENT,
            Required(
              Arg(
                'key',
                {
                  description: 'Key to get from config',
                }
              )
            )
          ),
          Command(
            'del',
            {
              alias: 'd',
              description: 'Delete config value',
              usage: `${PROGRAM} config del [options]`,
              examples: [
                `${PROGRAM} config del key`,
                `${PROGRAM} config del key --env production`,
              ],
            },
            ENVIRONMENT,
            Required(
              Arg(
                'key',
                {
                  description: 'Key to remove from config',
                }
              )
            )
          )
        ),
        Command(
          'run',
          {
            alias: 'r',
            description: 'Run arbitrary commands in the environment',
            usage: `${PROGRAM} run <command>`,
            examples: [
              `${PROGRAM} run build`,
              `${PROGRAM} run manage.py migrate`,
            ],
            callback: run,
          },
          Required(
            COMMAND
          )
        ),
        COMMAND,
        Flag(
          'version',
          {
            alias: 'v',
            description: 'Display version',
          }
        )
      )
    )
  ),
  process.argv
);