import {
  CliLeaf,
  CliFlagInput,
  CliStringArrayInput
} from '@alwaysai/alwayscli';
import { yesCliInput, cleanCliInput } from '../../cli-inputs';
import { appInstallComponent } from '../../components/app';

export const appInstallCliLeaf = CliLeaf({
  name: 'install',
  description:
    'Install this application and its dependencies locally or on a remote device',
  namedInputs: {
    yes: yesCliInput,
    clean: cleanCliInput,
    pull: CliFlagInput({
      description: 'Pull the base docker image prior to building'
    }),
    source: CliFlagInput({
      description: 'Specifically install the application source'
    }),
    models: CliFlagInput({
      description: 'Specifically install the application models'
    }),
    docker: CliFlagInput({
      description: 'Specifically install the application docker image'
    }),
    venv: CliFlagInput({
      description: 'Specifically install the application Python virtualenv'
    }),
    excludes: CliStringArrayInput({
      description:
        'One or more files to exclude from package. These will be appended to paths in .aai-ignore.',
      required: false,
      placeholder: '<path/to/file1> [<path/to/file2> ...]'
    })
  },
  async action(_, opts) {
    const { yes, clean, pull, source, models, docker, venv, excludes } = opts;
    await appInstallComponent({
      yes,
      clean,
      pull,
      source,
      models,
      docker,
      venv,
      excludes
    });
  }
});
