Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Using dep status -f, template operations don't work #1540

Closed
zkry opened this issue Jan 17, 2018 · 4 comments · Fixed by #1549
Closed

Using dep status -f, template operations don't work #1540

zkry opened this issue Jan 17, 2018 · 4 comments · Fixed by #1549

Comments

@zkry
Copy link
Contributor

zkry commented Jan 17, 2018

What version of dep are you using (dep version)?

❯ git describe --tags
v0.3.2-208-g3b8fbe48

Note: Running dep status normally:

❯ dep status
PROJECT                         CONSTRAINT                                 VERSION                                    REVISION  LATEST   PKGS USED
github.com/Masterminds/semver   branch parse-constraints-with-dash-in-pre  branch parse-constraints-with-dash-in-pre  a93e51b   a93e51b  1
github.com/Masterminds/vcs      ^1.11.0                                    v1.11.1                                    3084677   v1.12.0  1
github.com/armon/go-radix       branch master                              branch master                              4239b77   1fca145  1
github.com/boltdb/bolt          ^1.0.0                                     v1.3.1                                     2f1ce7a   v1.3.1   1
github.com/go-yaml/yaml         branch v2                                  branch v2                                  cd8b52f   d670f94  1
github.com/golang/protobuf      branch master                              branch master                              5afd06f   1e59b77  1
github.com/jmank88/nuts         ^0.3.0                                     v0.3.0                                     8b28145   v0.3.0   1
github.com/nightlyone/lockfile  branch master                              branch master                              e83dc5e   6a197d5  1
github.com/pelletier/go-toml    branch master                              branch master                              b8b5e76   9bf0212  1
github.com/pkg/errors           ^0.8.0                                     v0.8.0                                     645ef00   v0.8.0   1
github.com/sdboyer/constext     branch master                              branch master                              836a144   836a144  1
golang.org/x/net                branch master                              branch master                              66aacef   5ccada7  1
golang.org/x/sync               branch master                              branch master                              f52d181   fd80eb9  1
golang.org/x/sys                branch master                              branch master                              bb24a47   fff93fa  1

What dep command did you run?

First I run:

❯ dep status -f='{{.Constraint}} '
parse-constraints-with-dash-in-pre ^1.11.0 master ^1.0.0 v2 master ^0.3.0 master master ^0.8.0 master master master master

Then I want to do some logic with it:

dep status -f='{{if eq .Constraint "master"}}{{.ProjectRoot}}{{end}}'

template: status:1:5: executing "status" at <eq .Constraint "mast...>: error calling eq: invalid type for comparison

What did you expect to see?

The list of projects with constraint as master.

github.com/armon/go-radix github.com/golang/protobuf github.com/nightlyone/lockfile github.com/pelletier/go-toml github.com/sdboyer/constext golang.org/x/net golang.org/x/sync golang.org/x/sys

What did you see instead?

template: status:1:5: executing "status" at <eq .Constraint "mast...>: error calling eq: invalid type for comparison

Observations

It appears that the template fields Constraint, Version, and Latest suffer this problem becuase of their type declairation because of the type definition of BasicStatus. The fix would be to get convert these to a string before putting in the template. I can send the PR for this.

(Note: You can actually get this to work by running dep status -f='{{if eq .Constraint.String "master"}}{{.Version}}{{end}}'. This isn't that straight forward though.)

@darkowlzz
Copy link
Collaborator

Hi, thanks for trying it out and opening this issue. We have implemented status template output but its usage it not documented (#1497) and I think we can improve the implementation by fixing the issues you posted above. This would also help in clearly documenting the usage.

The fix would be to get convert these to a string before putting in the template. I can send the PR for this.

Thanks for digging into the issue. A PR would be great. Right now, since we use the fields in BasicStatus to calculate constraint, versions, etc, changing field types to string would break them. I think we can introduce another struct type with string as the values for all the fields. And this can also go into the documentation about template usage, keeping the underlying BasicStatus struct hidden.

Any simpler solutions are welcome 😊

@zkry
Copy link
Contributor Author

zkry commented Jan 19, 2018

Perfect. I'll do that. I'll can get the documentation in for #1497 too. I was thinking of putting a couple line message in the dep status -help output. Anywhere else you think it should be documented?

@darkowlzz
Copy link
Collaborator

@zkry Sorry for the delay. Yes, we should document it in status help output with all the available fields and I think we should have an examples flag for status, similar to dep ensure -examples where it would show a few examples of how to use the templates.

And maybe we could have more extensive documentation in a dedicate documentation page under docs/status.md in the future. I'll open a separate issue for it.

@zkry
Copy link
Contributor Author

zkry commented Jan 21, 2018

No problem. Ok, that makes sense. I can add the the -examples flag as well for this with some examples.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants