import {
  CliLeaf,
  CliStringArrayInput,
  CliStringInput
} from '@alwaysai/alwayscli';
import { yesCliInput } from '../../cli-inputs';
import { appPublishComponent } from '../../components/app';
import { echo } from '../../util';

export const appPublishCliLeaf = CliLeaf({
  name: 'publish',
  description: 'Publish a new version of your application to your project.',
  namedInputs: {
    yes: yesCliInput,
    name: CliStringInput({
      description: 'Release Name',
      required: false,
      placeholder: '<release_name>'
    }),
    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, name, excludes } = opts;
    const releaseHash = await appPublishComponent({
      yes,
      name,
      excludes
    });
    echo(`Published release ${releaseHash}`);
  }
});
