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

feat: treat empty catalog as jbanghub/jbang-catalog aliases #1738

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

maxandersen
Copy link
Collaborator

@maxandersen maxandersen commented Jan 23, 2024

prototype for #1733

lets you do:

jbang sqlline@/sqlline

and

jbang h2@/

basically treating "empty catalog" as a referring to "jbanghub"

@maxandersen
Copy link
Collaborator Author

hmm - test pass but have some other bugs :)

@maxandersen
Copy link
Collaborator Author

fixed it so it now works from command line - lets see if all other tests passes.

if (names.length > 2) {
org = names[0];
}
org = "jbangapp"; // TODO: should global default be controllable by config?
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 we should just make it a constant, just like Catalog.JBANG_CATALOG_JSON

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@maxandersen
Copy link
Collaborator Author

Should we accept h2@ to be equal to h2@/ and h2@jbangapp ?

quintesse
quintesse previously approved these changes Jan 23, 2024
@maxandersen
Copy link
Collaborator Author

ive updated so: h2@ is treated as blank catalog and thus maps to h2@jbangapp and sqlline@/sqlline works too

should we error on h2@/ or be lenient ? (we do already accept env@jbangdev/ before so I guess yes for consistency.

@@ -52,9 +52,10 @@ static CatalogRef get(String catalogName) {
if (catalog != null) {
catalogRef = catalog.catalogs.get(catalogName);
}
if (catalogRef == null && Util.isValidPath(catalogName)) {
if (catalogRef == null && (!catalogName.startsWith("/") || !catalogName.equals(""))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is causing the test failure...we are for some reason resolving local paths first to support somealias@/var/path/locally/ondisk ?

@quintesse what usecase is that for ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#1363 is what introduced bar@/some/file/on/disk

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the code to make it so paths that exist on disk will be honorored.

But I'm not too happy about it.

its only needed for when you use absolute paths...relative paths would be different.

I could also let it run through first and then if fails lookup in jbanghub as a fallback - to avoid scanning multiple times.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm guessing it basically because we also allow foo@http://url/to/jbang-catalog.json so to be consistent we also allow file paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

could accept file:// instead of raw path ?

Because as it is now a local dir will actually override an implicit catalog.

Jbang myapp@jbanghub and you have jbanghub locally will override jbanghub catalog.

Copy link
Contributor

Choose a reason for hiding this comment

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

could accept file:// instead of raw path ?

We could do that, yes. It does go somewhat against the fact that generally speaking a catalog reference is also a name@resourceref thing, so almost anything you should be able to pass to for example a //FILE tag was possible to use in a catalog reference. We'd now be limiting that. Now, I don't think anyone was actually using this, so we most likely won't be breaking anything, but just be aware that we will be making a breaking change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, I just checked the URI spec, it seems that file: doesn't allow relative paths, so in that respect using file: is not a good replacement. And that does seem somewhat wrong. You'd be forced to always use absolute paths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

hmm - I thought file:/./mydir was allowed but yeah does not seem to be "official" syntax.

URI.create("file:./pom.xml").getSchemeSpecficiPart() does let you fetch it though... but yeah not great.

@maxandersen maxandersen changed the title feat: treat empty catalog as jbangapp/jbang-catalog aliases feat: treat empty catalog as jbanghub/jbang-catalog aliases Jan 25, 2024
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.

2 participants