Skip to content

Add flag to pass a yml file as argument

Etienne Baqué requested to merge 50-json-file-as-param into master

Closes #50 (closed)

This MR leverages the --file option provided by the urfave/cli client we've been using for this project here.

As shown in these docs, specific function calls and data must be passed in to the Before and Flags hooks. And these will differ whether we use a --file option or the list of options that we're currently using.

So to support both ways of passing data (eg. via options or via a JSON file), this MR adds a new file called internal/flags/create_flags.go which introduces the PassedInFlags interface:

// PassedInFlags abstracts flags and before hook to specify in cli.Command,
// when creating a new release either with a file or with parameters.
type PassedInFlags interface {
	ListFlags() *[]cli.Flag
	BeforeHook([]cli.Flag) cli.BeforeFunc
}

The two functions to implement are a way to address the different content for the Flags and Before hooks, should we choose to pass a file (as outlined by the docs).

Manual testing

New demos (2022-11-25):

💻 Create a release using a file:

video_output-2022-11-25_15.46.48

💻 Help text for create and create-from-file:

video_output-2022-11-25_16.30.52

Previous demo recording: https://youtu.be/3PWeHqk0QPw

Lately, here's the local release.yml file I've been using:

---
name: Release Name
description: create release with a file
tag-name: v1.5.2
ref: master
assets-link:
  - '{"name":"asset1", "url":"https://gitlab.com/gitlab-org/release-cli", "type":"other", "filepath":"/bin/binary_file"}'
  - '{"name":"asset2", "url":"https://gitlab.com/"}'
ref: abcdefgh12345678
milestone:
  - 'v2.0'
  - 'v3.0'
Edited by Etienne Baqué

Merge request reports