Skip to content

Conversation

cmbahadir
Copy link
Contributor

@cmbahadir cmbahadir commented Aug 15, 2019

Just wanted to contribute with below concerns;

  • Description and name of the argument (chosen as "index").
  • Location of the tests
  • And also i am new to go world. :)

Fixes: #199

Signed-off-by: Cihan Mete Bahadir c.mete.bahadir@gmail.com

@@ -66,18 +68,28 @@ type composeSetDefaultCmd struct {
Command `name:"set" short-description:"Set the active docker compose file" long-description:"Set the active docker compose file"`

Args struct {
Version string `positional-arg-name:"version" description:"Either a revision (tag, full sha1) or a URL to a docker-compose.yml file"`
Index string `positional-arg-name:"index" description:"Index of the docker compose file returned from 'sourced compose list'"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it makes sense to accept both the index and the name?
I see why index can be better in many cases but at the same time, it's easier to switch to master just by typing sourced compose set master instead of listing the files and looking for the correct number.
what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean only for master or all rev and URL?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it should work as now + with index. So essentially the tests that are already in master should pass without any change, then it should also work with indexes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that it's safe to try parsing whether it's an integer first and in case of a parsing error fallback to the current mechanism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is a branch, or tag called 1?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's definitely a case that I thought, but it's really and edge case that IMHO could be ignored. I don't think that it makes much sense to have a branch named \d+. But if you prefer you may want to default as integer and provide a flag --rev to force it. But again IMHO it's unnecessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We control tags and branches so there is no need to add additional logic for the edge case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What git does, for example when performing a checkout to a revision that can be resolved to different commits, is to rise an error, and ask for a more precise definition of the revision.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed it to both accept index and name by ignoring the edge cases.

active := files[index]
err = composefile.SetActive(active)
fmt.Println("Active docker compose file was changed successfully.")
fmt.Println("To update your current installation use `sourced restart`")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's happening if the user inits with one config using services a,b,c changes to a new compose defining services c,d, and then the user restarts?
Isn't it error prone because the potential mismatch between old and new config? Or can we assume it's stable enough for oficial versions?
Should that problem be handled by the user depending on initial and final compose configs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it enough to check SetActive error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is more an open question for @src-d/applications, to consider if we want to handle that edgecase, or if it should be handled by the user running prune before changing the active compose.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is something to be discussed in the DD about sourced upgrade. IMO if the changes in the services occurred because of an upgrade of sourced (so something expected), then it should be handled by the upgrade process, or in case that it's not possible, it should be correctly notified to the user. Otherwise, if the change occurred because the user is using a custom compose file, then he/she is an advanced user and I would assume that he/she knows what to do.

@cmbahadir cmbahadir force-pushed the singlePullRequest branch 2 times, most recently from 8cc3e56 to 3ae3561 Compare August 19, 2019 18:59
…te Bahadir <c.mete.bahadir@gmail.com>

Added tests for compose list/set commands. Signed-off-by: Cihan Mete Bahadir <c.mete.bahadir@gmail.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
…an Mete Bahadir <c.mete.bahadir@example.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
… <c.mete.bahadir@example.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
…ahadir@gmail.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
…ahadir <c.mete.bahadir@gmail.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
Copy link
Contributor Author

@cmbahadir cmbahadir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Added the error check for SetActive
  • Modified tests to run properly on windows.
  • changed the .gitignore to not include .vscode

@smacker
Copy link
Contributor

smacker commented Aug 21, 2019

Thank you @cmbahadir, great work!
Do you think you can implement a fallback described here: https://github.com/src-d/sourced-ce/pull/214/files#r315101967 ?

I think you can ignore the edge case with a number as a tag or a branch for now, we can improve it later.

@cmbahadir
Copy link
Contributor Author

cmbahadir commented Aug 21, 2019

Thank you @cmbahadir, great work!
Do you think you can implement a fallback described here: https://github.com/src-d/sourced-ce/pull/214/files#r315101967 ?

I think you can ignore the edge case with a number as a tag or a branch for now, we can improve it later.

Hi @smacker yes i can implement it but i may need an additional package like ‘reflect’ is it ok to use it?

@smacker
Copy link
Contributor

smacker commented Aug 21, 2019

Please help me understand why do you need reflect?

Currently you have

index, err := strconv.Atoi(c.Args.Index)
if err != nil {
  fmt.Println("Provide the index of the docker compose file in 'sourced compose list'")
}

The idea is to try to go old code-path aka composefile.SetActive(c.Args.Index) in such case instead of showing the error. (argument's help text needs to be updated too)

@cmbahadir
Copy link
Contributor Author

cmbahadir commented Aug 21, 2019

Yes @smacker you are right just thought that it may be safer to check the type of the index. I will implement it by handling fallback from strconv.Atoi ;)

…. Signed-off-by: Cihan Mete Bahadir <c.mete.bahadir@gmail.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
active := files[index]
err = composefile.SetActive(active)
} else {
fmt.Println("Index is out of range of the files in 'sourced compose list'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of printing the message and return nil, this should be
return fmt.Errorf("Index is out of range of the files in 'sourced compose list'")

Since the argument is not valid, a non-0 exit makes sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the reviews, i will apply the fixes.

active := files[index]
err = composefile.SetActive(active)
} else {
fmt.Println("Index is out of range of the files in 'sourced compose list'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me too.

@se7entyse7en
Copy link
Contributor

se7entyse7en commented Aug 23, 2019

BTW thanks for your contribution @cmbahadir, we really appreciate it! Gonna approve after the last nit-picks 👍.

… return. Signed-off-by: Cihan Mete Bahadir <c.mete.bahadir@gmail.com>

Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
@cmbahadir
Copy link
Contributor Author

All changes implemented.

@smacker smacker merged commit 4de8f56 into src-d:master Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to pass an index number with sourced compose set
5 participants