-
Notifications
You must be signed in to change notification settings - Fork 168
feat: handle documentation references both in source references and in alias catalog #2013
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
base: main
Are you sure you want to change the base?
Conversation
e4220d3
to
c0ae56a
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.
A good first step! But there's one important change that has to be made, which is to change the type of docs from String
to ResourceRef
. I've left comments on the relevant sections. It makes the code slightly more complicated but it makes sure the existing machinery in JBang takes care of locating the files.
@@ -308,3 +317,42 @@ public Integer doCall() throws IOException { | |||
return EXIT_OK; | |||
} | |||
} | |||
|
|||
@CommandLine.Command(name = "docs", description = "Open the documentation file into the default browser.") |
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.
Change "into" -> "in"
} | ||
|
||
private static URI validateDocsReferenceAndTransformToUri(ScriptInfo info) { | ||
if (info.docs.startsWith("http")) { |
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.
Once the type of info.docs is ResourceRef
none if this is necessary because that type handles all of the URL vs absolute vs relative paths etc.
@@ -37,6 +37,7 @@ public class Project { | |||
private final Map<String, String> manifestAttributes = new LinkedHashMap<>(); | |||
private String javaVersion; | |||
private String description; | |||
private String docs; |
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.
The type of this shouldn't be a String
but a ResourceRef
@@ -180,6 +181,17 @@ public Project setDescription(String description) { | |||
return this; | |||
} | |||
|
|||
@Nonnull | |||
public Optional<String> getDocs() { |
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.
Same here, use ResourceRef
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.
Much better, there's still a couple of minor things and one major must fix item.
.findFirst(); | ||
} | ||
|
||
private static ResourceRef createResourceReference(String s) { |
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.
No, this isn't how it's supposed to be done, you have to use the resolver. Like I said before, don't worry about things being downloaded, that's something we can fix later.
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.
Honestly I don't understand. If use the resolver in thegetDoc
like in the following code:
public Optional<ResourceRef> getDocs(ResourceResolver resolver) {
return getTags()
.filter(this::isDocsDeclare)
.map(s -> s.substring(DOCS_COMMENT_PREFIX.length()))
.map(resolver::resolve)
.findFirst();
}
The problem I face is that when execute the jbang info docs <sometfile_with DOCS_tag>.java
is that it tries to resolve. So if it point to a relative that I know exists:
[jbang] [ERROR] Could not find ./itests/this_exists.txt
or if referring to an url it tries to download the URL, while it shouldn:
[jbang] [ERROR] Could not download http://google.com
If I add the resolution I don't foresee a way to correctly execute the command.
@andsel I updated your PR to make it work. The issue was the URL you were testing with, for now it must refer to an actual file or page |
bffa14b
to
4d5c656
Compare
@quintesse thank's a lot for the addition, so it has to always download the url and then let it open in the browser. I'll proceed by aligning the documentation. |
4d5c656
to
7255f14
Compare
No, that's just a temporary implementation detail that can be fixed later. It's of no consequence to the docs feature. |
@andsel if you rebase again against the latest version of "main" then you'll have access to lazy resource refs that I just added: #2031 You can update the code like: prj.setDocs(tagReader.getDocs(LazyResourceResolver.lazy(resolver1)).orElse(null)); Although perhaps we can even use it for the shared resource resolver (but that would have to be thoroughly tested): ResourceResolver resolver1 = LazyResourceResolver.lazy(new SiblingResourceResolver(resourceRef, ResourceResolver.forResources())); |
@quintesse which is the best place to document this feature?
|
To be honest, there currently is no "best place". We are sorely missing some organization in our docs.
It's too small a feature IMO to merit its own page
Well, then we should add all options to that page because all tags can be overridden by passing arguments to the alias. So no I don't think that's a good option either. The real issue here is, IMO, that we're missing a page that simply shows what //-tags are available and what they are used for. Yes, a bunch of them are sprinkled throughout the docs but we're missing something that says: these are all the ones and this is what they do. In such a page we could then show for each tag what the corresponding command line option is (eg //JAVA vs --java). |
About the documentation point:
I've created the issue #2032 to address this (I may work on it, so eventually please assign to me) |
04944c1
to
760deb7
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.
Almost there!
Btw, I'd be willing to merge this PR without the docs and leave that to be done in #2032 |
…ed. When the file path is relative, it tries to use project mainSource, or if not available consider current working dir.
…e catalog (if present)
… builder during project creation
0c5a911
to
7984ce5
Compare
cac4902
to
538b650
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.
LGTM
@quintesse thanks a lot for your all your guidance on this! :-D |
And thank you for your implementation and in moving this issue forward! :-) |
Feature description
Implements a new
DOCS
directive that permit insert a link or file reference that contains the documentation for the script. The documentation reference can be also assigned to an alias of a script and in that case takes precedence over the directive present in the script.The documentation reference can be opened with a newly added info subcommand, name docs, like:
Describe changes at code level
The main change is to collect and resolve the reference present in the new
DOCS
directive inTagReader.getDocs
.During JBang project creation or update the docs reference is collected and stored, to be later read in the
ScriptInfo
helper class.On the
cli.Alias
command a new--docs
parameter is added to be accept a manually provided doc reference and store in the catalog. This catalog information is used in theScriptInfo
's initialization, after a resolution to a ResourceRef, to eventually overwrite the directive coming form the script.How to test
Use a script like following for the testing part:
Build a new JBang distribution and and uncompress in tmp folder:
In the same
tmp
folder create a new filethis_exists.txt
with some content.Browse doc from script
Opens a browser or an editor.
Browse doc from alias
Add an alias overriding the file's contained directive and check it opensù
Check it opens the web browser to https://www.jbang.dev/documentation/guide/latest/javaversions.html .
Remove the alias
Add an alias without a docs ref forcing
Verify if opens the editor or the browser pointing to the resource defined in the first
DOCS
directiveDev tasks