Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow a project to be specified using the downloadSource flag #3000

Closed
4 tasks
Kamran64 opened this issue Apr 27, 2020 · 6 comments · Fixed by #3044
Closed
4 tasks

Allow a project to be specified using the downloadSource flag #3000

Kamran64 opened this issue Apr 27, 2020 · 6 comments · Fixed by #3044
Assignees
Labels
kind/user-story An issue of user-story kind

Comments

@Kamran64
Copy link
Contributor

Kamran64 commented Apr 27, 2020

/kind user-story

User Story

As a developer, I'd like to be able to specify a specific project (by name field) to be downloaded from the --downloadSource flag on odo create. Currently, using the flag only downloads the first project in the devfile.

Acceptance Criteria

  • Add an optional argument to --downloadSource which downloads the project specified by the argument. The argument will be the name field of the project definition e.g. nodejs-web-app
  • If no argument is supplied to --downloadSource, default to the first project as we have in todays implementation.
  • If a project name doesn't match a project in the devfile or there are multiple projects with the same name, we should fail.
  • Resource creation will only be triggered if:
  1. The experimental flag has been enabled
  2. The component is a devfile component
  3. There is a project defined in the devfile of the given component
  4. odo create command called with a --downloadSource flag

Usage

  • Set odo to experimental mode

  • Run an odo create <component-name> --downloadSource and optionally specify a project using --downloadSource=<project-name>.

  • Resource creation will only work if there is a project listed in the devfile,

Links

/kind user-story

@openshift-ci-robot openshift-ci-robot added the kind/user-story An issue of user-story kind label Apr 27, 2020
@Kamran64 Kamran64 changed the title Allow a project to be specified from the downloadSource flag Allow a project to be specified using the downloadSource flag Apr 27, 2020
@Kamran64
Copy link
Contributor Author

/assign

@Kamran64
Copy link
Contributor Author

Kamran64 commented Apr 28, 2020

A couple of thoughts after looking at implementing this yesterday:

  1. The --downloadSource flag is currently a bool value. If we change it to hold a string, then it becomes mandatory that a value is entered after the flag is invoked which defeats the purpose of acceptance criteria 2.

  2. The other option is to keep the flag as a bool but check for a non flag argument passed after the flag (similar to how the component name is passed). However, if we do this: how do we differentiate between whether a component name is passed or project to be downloaded since both arguments are optional.

    • E.g. if a user passes odo create nodejs --downloadSource my-component how do we know if they're trying to specify a project after downloadSource or if they're just trying to name their component?

@elsony @johnmcollier - What are your thoughts on this?

@Kamran64
Copy link
Contributor Author

Kamran64 commented Apr 28, 2020

Solutions considered are:

  • We make it mandatory that if a component name is being provided, then it must come before --downloadSource and we assume that the arg after (if any) is the project to be downloaded.

  • Add a new flag to specify the project to be downloaded - However this may not be nice for the user experience (might be confusing to differentiate between --downloadSource and this new flag.)

  • Keep --downloadSource as it is and if there is more than one project in the devfile, trigger interactive mode to allow the user to choose the project. This won't work in cases where project creation is automated though.

@Kamran64
Copy link
Contributor Author

For now, we'll go with implementing this in interactive mode if there is more than one project in the devfile. However, we will need to consider how a user can specify this information from the command line in future.

@Kamran64
Copy link
Contributor Author

Kamran64 commented Apr 29, 2020

We've found that we can use NoOptDefVal to pass the flag a default value is one is not specified. As such:

  • If there is only one project in the devfile we only download that one if no project is specified.
  • If a project is specified, we validate that project exists and then download it.
  • If there are multiple projects and one is not specified, we enter interactive mode to allow the user to choose.

Due to limitations of the NoOptDefVal attribute, the format must be --downloadSource=projectName. See: spf13/pflag#134

@Kamran64
Copy link
Contributor Author

Reposting potential solutions here after further discussion (along with drawbacks)

  • We continue to use the NoOptDefVal attribute to assign the flag a default value if the user hasn't passed an arg. However this makes it mandatory that is a user wants to pass an arg they have to do so in the format downloadSource=<project-name. This may be confusing and breaks consistency with other flags but it may be the cleanest solution code wise.

  • We add a new flag specifically for downloading a specific project. --downloadSource will continue to download the first project but you can use this new flag to download a specific project. This will be poor for user experience too and confusing to have two similar flags.

  • We keep the --downloadSource flag as a bool and look at the argument as a non flag arg. However, this will require us to find some way to differentiate between whether the component name was passed or the project to be downloaded. We could look at the arg after the flag and check to see if this is a valid project first, otherwise we add it as a component name. I played around with this solution earlier and it looks like it would involve a lot of hacking around with args so may be messy for the codebase. Not ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/user-story An issue of user-story kind
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants