-
Notifications
You must be signed in to change notification settings - Fork 52
Added Index numbers for compose files to be used in "compose list/set" #214
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
Conversation
6368ee0
to
0d738cd
Compare
cmd/sourced/cmd/compose.go
Outdated
@@ -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'"` |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cmd/sourced/cmd/compose.go
Outdated
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`") |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
8cc3e56
to
3ae3561
Compare
…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>
3ae3561
to
3473633
Compare
…ahadir <c.mete.bahadir@gmail.com> Signed-off-by: cmbahadir <c.mete.bahadir@gmail.com>
1a2ea1f
to
a8a51d9
Compare
There was a problem hiding this 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
Thank you @cmbahadir, great work! 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? |
Please help me understand why do you need 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 |
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>
6979870
to
d39a8d1
Compare
cmd/sourced/cmd/compose.go
Outdated
active := files[index] | ||
err = composefile.SetActive(active) | ||
} else { | ||
fmt.Println("Index is out of range of the files in 'sourced compose list'") |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
cmd/sourced/cmd/compose.go
Outdated
active := files[index] | ||
err = composefile.SetActive(active) | ||
} else { | ||
fmt.Println("Index is out of range of the files in 'sourced compose list'") |
There was a problem hiding this comment.
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.
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>
All changes implemented. |
Just wanted to contribute with below concerns;
Fixes: #199
Signed-off-by: Cihan Mete Bahadir c.mete.bahadir@gmail.com