I wrote a CLI over shards that adds and removes shards from a project, can search for shards, visualize dependency trees of shards, and more

Since shards CLI lacks the add and remove commands for shard.yml, along with others like shards info, etc…

Demo

2 Likes

Probably would help if you included a link to the actual code/how to get/use it versus just a video :sweat_smile:.

1 Like

Probably would help if i cared. lol

You can get it from github.com/navid-m/sword

1 Like

Sword looks like a very useful tool, but since it’s licensed under GPLv3, it’s unlikely that its code could be incorporated into shards, which is under the Apache License 2.0. That’s a bit unfortunate.

You’re not the first one with this idea.
Are you aware of GitHub - nedpals/sharn: Managing shards made easier. ?
Also relevant is the upstream issue: shards add/get · Issue #144 · crystal-lang/shards · GitHub
Unfortunately, nobody has yet implemented this in a way that it preserves the YAML layout without removing comments and extra whitespace, for example.

1 Like

Its as much of an idea as putting two wheels on a bicycle is an idea. The first commands anyone uses in a package manager is add and remove packages, it should’ve been in the shards CLI years ago. No one wants to edit the yaml manually.

Comments are still preserved, btw.

I meant the idea to fill this deficiency and actually build a tool, a wrapper for shards to provide the missing features.

That’s great!

The implementation looks similar to the concept I had suggested in shards add/get · Issue #144 · crystal-lang/shards · GitHub
There’s a lot more complexity to account for updating an existing entry, of course.

I find all this manual YAML editing a bit concerning though. So many things that could break. :see_no_evil_monkey:

I think the add and remove commands implementation are more or less what I would imagine for shards directly. I have some feedback/concern

  1. I was worried about mismatched indentation within the yaml since you are not checking how other nodes in the yaml doc are indented. But it seems yaml doesn’t care. :person_shrugging:

  2. To avoid breaking file having an approach of writing the result to new file, then checking if the file is a valid yaml, and just then replace the user’s content would give me more confidence. It also give us a point to prompt the user to report a bug.

  3. There is no support for development_dependencies

  4. I would like some syntax like shards add owner/repo shards add github:owner/repo shards add github:owner/repo@revision, etc. as a shorthand for adding github and other providers.

@straight-shoota , WDYT? If those changes are sent to shards as PR with maybe the strategy to avoid breaking files would does be a good addition?

2 Likes

This sounds nice.
I think it can actually work entirely in memory, without juggling files.
And on top of checking if it’s valid, we could even validate the content. I.e. parse the original YAML and mutate its YAML::Any structure in parallel to the text-based manipulation. Then check if both results are semantically equivalent.

I’m all in for that. This has been on the table for a long time, just nobody has picked it up yet.

There is of course the opportunity to implement a round-tripping YAML thing like ruamel.yaml but it’s difficult.

1 Like

@god would you be interested in making a PR to shards directly with this idea? Or at least with the current implementation and we can add the safety nets and extensions.

If not, do you give consent to pick your work and incorporate it to shards?

I’m busy with something else atm, will probably submit a PR with the same implementation I’ve just done after 19:00 UTC on the 10th, could take longer.

1 Like

It was easier than expected and took a few minutes. PRs up hahah.

3 Likes

For reference: Add remove and add commands by navid-m · Pull Request #672 · crystal-lang/shards · GitHub

1 Like