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

Renamed ping to info in store #8975

Closed
wants to merge 13 commits into from
Closed

Renamed ping to info in store #8975

wants to merge 13 commits into from

Conversation

vicky1999
Copy link
Contributor

@vicky1999 vicky1999 commented Sep 13, 2023

Motivation

I have renamed the command store ping to store info

Context

This change is required in #8914

Changes made:

  • First, in main.cc, I have updated the command from ping-store to info-store and accordingly changed the command values
  • In info-store.cc, command was changed to info
  • Renamed ping-store.cc to info-store.cc
  • Renamed store-ping.sh to store-info.sh
  • Updated the doc info-store.md
  • To display true/false value for trusted, I made a condition if trusted has any value other than 0/false, then display true or else display false. After making this change, the json and store info is giving true/false for trusted instead of int

Screenshot

image
image

Priorities

Add 👍 to pull requests you find important.

@github-actions github-actions bot added documentation new-cli Relating to the "nix" command with-tests Issues related to testing. PRs with tests have some priority labels Sep 13, 2023
Copy link
Member

@thufschmitt thufschmitt left a comment

Choose a reason for hiding this comment

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

Thanks, left a couple of comments, but looks good overall. Great to see someone help tacking this :)

src/nix/main.cc Outdated
@@ -126,7 +126,7 @@ struct NixArgs : virtual MultiCommand, virtual MixCommonArgs
{"ls-store", {"store", "ls"}},
{"make-content-addressable", {"store", "make-content-addressed"}},
{"optimise-store", {"store", "optimise"}},
{"ping-store", {"store", "ping"}},
{"info-store", {"store", "info"}},
Copy link
Member

Choose a reason for hiding this comment

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

That one shouldn't be changed. The ping-store alias should stay the same.
We should also have a backwards-compat alias from store ping to store info I think. @Ericson2314 @edolstra is there a mechanism for aliasing subcommands? If not we can always do it manually

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. So, According to the comment, the ping-store need to stay the same but, the vector alias of it {"store", "info"} can be as it is. please let me know if this is the expectation

Copy link
Member

Choose a reason for hiding this comment

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

I do not off-hand know of a mechanism for aliasing within subcommands, but if we look how this is implemented with overriding rewriteArgs, perhaps that can be done within the Store command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed the store command in store-info.cc. After that, I had a suggestion that, if we are renaming the command from ping to info, then I thought it would be better to also update the alias accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure what you are saying? I am saying you can modify src/nix/store.cc to that nix store ping is an alias for nix store info in addition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please let me know if there are any documentations available for this aliasing.

Copy link
Member

Choose a reason for hiding this comment

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

There is no documentation for this exact task. You would need to figure out what main.cc is doing and recreate it in store.cc. I am sorry.

It would be good to add API docs to rewriteArgs where it is declared (args.hh). Perhaps once you've figured out what is going on your can do that, so the next person is less stuck?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will try to implement it in store.cc. Thanks.

return
#include "ping-store.md"
;
return #include "info-store.md"
Copy link
Member

Choose a reason for hiding this comment

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

Not a big deal (and no blocker to me), but since we're renaming things, we could rename this to store-info.md to match the command (ping-store comes from the original command name and was already out of sync)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

store-info files are renamed according to the command name

Copy link
Member

Choose a reason for hiding this comment

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

I think what @thufschmitt is saying is that it would be good to call both files store-info.{cc,md}. The file was never properly renamed when the commands were made hierarchical before, but we should fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. I will try to implement the aliasing in store.cc. Thanks

@@ -41,9 +41,9 @@ struct CmdPingStore : StoreCommand, MixJSON
if (auto version = store->getVersion())
res["version"] = *version;
if (auto trusted = store->isTrustedClient())
res["trusted"] = *trusted;
res["trusted"] = *trusted ? true : false;
Copy link
Member

Choose a reason for hiding this comment

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

We should eventually not need this via the enum struct change I proposed for TrustedFlag, but it is fine to do this for now and that in a follow-up PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure. I saw that TrustedFag is storing only bool value. But, somehow the value is printing 1/0 instead of true or false. So, I added this condition here.

Copy link
Member

Choose a reason for hiding this comment

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

It's because it is the wrong type of enum. The other type of enum will remove the implicit coercions that are causing the problem here.

@fricklerhandwerk fricklerhandwerk added the RFC Related to an accepted RFC label Sep 14, 2023
@vicky1999
Copy link
Contributor Author

Another update regarding the store info --json command. I have made the JSON to be displayed with formatting.

image

@thufschmitt thufschmitt added the idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. label Sep 15, 2023
@vicky1999
Copy link
Contributor Author

@Ericson2314 I tried to add the aliasing in store.cc. But, it seems that, args.cc is throwing an error if no subcommand exist matching the list of subcommands. So, I made some changes to args.cc and made the alias implementation under args.cc. Need your suggestion on this.

Kindly please review the commit: fc094c1 and let me know if it is ok.

} else {
nlohmann::json res;
Finally printRes([&]() {
logger->cout("%s", res);
logger->cout("%s", res.dump(2));
Copy link
Member

Choose a reason for hiding this comment

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

What is this change? formatting the JSON?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is about formatting the json like in the screenshot below:
image

Without the change, the json looked like:

{"trusted": true, "url": "local", "version": "2.1.0"}

I added the code to view the json with some indents ans spaces to give a better to view for this json command.

Copy link
Member

Choose a reason for hiding this comment

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

We do not usually format output json, so I for consistency I don't think we want to here either. If we decide to do so, it should be across the board not a one-off decision for one command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I will revert the changes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ericson2314 the changes related to aliasing which was done in args.cc and store info json formatting were reverted. i will try the new approach you mentioned for aliasing in main.cc.

@Ericson2314
Copy link
Member

@vicky1999 See CmdFlakeInfo for an existing alias/deprecation we have. It's not a great way to do it but we can just do it that way for now.

@vicky1999 vicky1999 closed this by deleting the head repository Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation idea approved The given proposal has been discussed and approved by the Nix team. An implementation is welcome. new-cli Relating to the "nix" command RFC Related to an accepted RFC with-tests Issues related to testing. PRs with tests have some priority
Projects
Status: 🏁 Review
Development

Successfully merging this pull request may close these issues.

4 participants