-
Notifications
You must be signed in to change notification settings - Fork 1
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
Self-documenting scripts #7
Comments
Think of a mecanism to make documentation convenient to write contextually. For instance: allow for documenting before each function and each variable, then concatenate all the docstrings together. |
ce0b2c1 fixes this. Example:
@fictionic: What do you think? |
@fictionic: I've just commited a substential amount of changes:
See the "Breaking changes" section in the readme. Another significant improvement in my opinion: the |
I'm utlimately planning to embed the "godoc" document into the program, accessible via a I'm thinking of dividing it into sections that can be specified as an option:
|
|
Yes, I'll make the `-h` queries work on regexp.
As for 15-discfrompath, it's as modular as it gets. We can incorporate
further elements of tag inference later, no problem with that.
For now I felt that it was very needed, so I just went ahead.
`intro`/`doc`: This would basically most of this page:
https://godoc.org/github.com/Ambrevar/demlo
So everything that relates the general concepts of Demlo but nothing
specific to some scripts in particular.
|
Wait, should they work on regexp, or just a literal match of the script name minus the number prefix? What help info should be displayed if a regex matches multiple scripts? |
Ah, I see. May I suggest establishing a naming scheme for the tag extraction scripts, so they can all be called at once with a regexp? Like |
Maybe all of them separated by sections holding their names.
What do you think?
|
I was going to rename all files.
I think `extract` is not obvious enough. Why not `tag`?
|
That could work. The other option would be to tell the user which scripts match, and let them run the command again with an exact name. This would let |
Well because 'tag' also refers to the process of cleaning up the existing tags. Is anything else besides tags extracted? If, not I think 'extract' is a good bet. You could always do |
Here is a counterargument to complete modularization of the tag extraction scripts. If the user wants to extract a very particular set of tags, it's much more annoying to list each script on its own, rather than supply something like |
The available scripts are always printed at the beginning of a run.
I think Demlo should just go ahead instead of being pedantic, it makes
for a smoother experience.
|
This is true. But if everything is modularized, looking through them could be a hassle. Do you not think it would be helpful to provide a sort of search functionality? Use case: "I wonder what sort of scripts there are relating to tags... |
Precisely, so I also want to rename `10-tag.lua`.
"Extract", without more information, does not give away much about
what it does. In the end, all we are doing is "setting the tags".
I propose the following:
- 10-tag-normalize
- 15-tag-discfrompath
- 18-tag-case
|
What does "extract a particular set of tags" mean?
`-pre 'textr = {"title", "track", "album_artist"}'`
This is not much shorter than, say, `-s tag-title -s tag-track -s
tag-albumartist`.
Plus you get completion with the `-s` argument.
But again, I don't really know your use-case.
|
I may be right. But if we have completion, then requiring the exact
name is fine too.
Let me sleep over this.
|
Hm, I don't know how So in my system, the role of the tag extraction scripts is more than "setting" the tags—it is either to fill in missing tags for later processing (the most common case), or to override the existing tags (which requires a flag to be passed, in demloconf).
Good point. I concede this may be superior, so long as the extraction scripts can be easily refered to by regexps. The only problem is how to specify which extracted tags should override the existing ones (as described above). What do you think about this? |
Your approach certainly has its benefits and seems very powerful, but it
requires quite some effort to grasp. Demlo is not that approachable
already, I don't want to make it more obscur than it already is.
Let's not forget that Demlo can fetch tags from MusicBrainz with the
`-t` option, it should provide for good results at a decent speed.
At this point, I'm wondering if all the extra complexity isn't unnecessary.
Hm, I don't know how `normalize` and `case` would work or interact.
`case` is run after `normalize`, so it works on its result. It can also
run without `normalize`. The three scripts work on tags.
The only problem is how to specify which extracted tags should override the existing ones (as described above). What do you think about this?
Why wouldn't it work with the command I suggested above, assuming those
scripts do just that, setting one specific override.
If I misunderstood what you meant, please provide a detailed use-case.
|
I find that tag databases are too inconsistent to be used in my library. And as for the complexity, I believe that a correct titlecase algorithm is simply going to be complex.
But what exactly does
How would you indicate that you want to extract a particular tag if and only if it doesn't already have a value in the file? |
`normalize` is a little monolithic right now, it removes all unwanted
tags and normalizes the genre.
Maybe we could split it into additional scripts.
How would you indicate that you want to extract a particular tag if and only if it doesn't already have a value in the file?
Something along the lines of
```
if empty(o.title) then
o.title = extract_title(i.path)
end
```
?
|
Yeah I think that's best. Those bits of functionality seem pretty different.
How would that work from the command line, though? It seems like a strategy where all tags that can be extracted are extracted, but saved somewhere, and then the cmdline arguments tell Demlo which tags to actually put into the file. Using a function |
OK, now I understand what you mean. I'll think about something. I you can make your current implementation as minimal and modular as possible, a PR would be very welcome! |
|
Problem: the |
It's not possible, Lua and Go are not expressive enough to do that. At
least not easily with the current code.
I'm realizing now that Go+Lua was probably a mistake, but that was a few
years ago and I didn't have enough experience to see that coming.
That said, can you tell precisely what fails in your case?
As far as Demlo is concerned, scripts are meant
to be able to run independently from each other.
|
I define a table
|
This is to be expected. Look how the other global variables are
declared. You should do something like this:
local localsettings = settings or {} -- '{}' is the default value, can be anything.
-- ...
foo = localsettings["option"]
If your settings have sub-tables or function calls, your code should
either ensure the structure integrity is correct and provide appropriate
defaults, or always handle nil cases safely.
If you really want to stick to a monolithic approach, you can simply
exit your script when `settings` is nil:
if settings == nil then return end
|
Ok yeah. I'll do that. Somewhat related: Do you think there would be good reason to expose a non-debug print function to the scripts, so they could tell the user things like "settings is not defined; aborting"? |
Well, this goes together with the `input` functions we mentioned in
another issue. `input` needs some form of printing, so it has to be
there at some point.
I don't see much use for printing beside that.
|
Here's an argument in favor. Often when I run my scripts, I don't immediately understand what it's doing in a certain case; I need to pass As I see it, the scripts can get complex enough to the point that the user won't be able to figure out exactly what will happen in every case, so it would be very helpful if they could give the user some hints about their behavior. |
You can already implement that yourself. For instance, with a
`debug_level` global variable:
```
function info(s)
if debug_level >= 1 then
debug(info_prefix .. s)
end
end
…-- ...
info("My info string")
```
Then call
```
$ demlo -debug -pre 'debug_level=1' ...
```
Would that be enough?
|
Yes but this doesn't let you print in different colors! Maybe allow an optional argument to |
Well, coloring is done via ANSI escapes, which is ugly and brittle. I
don't think this should be a key requirement for Demlo...
Focusing on an Emacs interface seems much more sensible in my opinion.
That said, what do you want to print in color? The prefix?
I could also export a more low-level `print` function I guess.
|
Oh certainly not. Just an enhancement.
You're on your own on that front, heheh. I have zero use for an emacs interface.
Yes. Currently debug messages are printed with |
Closing this. Regarding the other points, we can further discuss them in their dedicated issues. Regarding the Emacs interface: it does not mean that you have to use Emacs as your primary editor. Think of Emacs as a toolkit. Wait for it, you might be surprised... :) |
Add a
-h
commandline flag which displays the documentation of a script, then exits.The flag could be called several times.
The documentation could be stored in a global variable.
The text was updated successfully, but these errors were encountered: