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

favour or at least mention single-letter options #8046

Closed
blueglyph opened this issue Apr 23, 2022 · 37 comments
Closed

favour or at least mention single-letter options #8046

blueglyph opened this issue Apr 23, 2022 · 37 comments
Labels
decision A (possibly breaking) decision regarding tldr-pages content, structure, infrastructure, etc.

Comments

@blueglyph
Copy link

The guildelines specify:

Try to incorporate the spelled-out version of single-letter options in the example's description. The goal is to allow people to understand the syntax of the commands, not just memorize it.

Actually the purpose is to give practical examples of commands that are often used. For example, nobody ever types

sudo pacman --sync --refresh --sysupgrade

Instead, people type:

sudo pacman -Syu

That's also what you'll see people try to help you out. "Have you tried pacman -Syu?". Hmm, what does it do, let's check with tldr... and no luck, it's not there. Back to the man pages then.

So while it is interesting to see there are spelled-out options, it is redundant with the description above the command (Synchronize and update all packages:), and not very practical. Sure, I can check the man page for find the equivalent, but then this makes these pages irrelevant.

As a suggestion, it would be best to have at least the practical alternatives for long commands:

Synchronize and update all packages:

      sudo pacman --sync --refresh --sysupgrade
      sudo pacman -Syu
@pixelcmtd
Copy link
Member

I have to agree with both the original rationale and your example of it failing.

Our goal is to provide users an alternative for quickly looking up how to use a command in a beginner-friendly way, not how to master it. That's why we should, as we currently do, prefer GNU options.

But yes, nobody types pacman --sync --refresh --sysupgrade into their terminal, and if they would, they would waste their time massively. Everyone uses pacman -Syu without remembering (or maybe not even having known in the first place) what any of that actually means. I can definitely see, how the latter would be more helpful here (mentioning both like you suggested is also somewhat of a good idea).

I think these sentences at least need a little change: GNU (or long) options are preferred/the default, but Unix (or short) options are fine in certain cases.

Another option, and I think that this would be even better, is a standardized or for options. We already use pipes for or (i.e. tldr 7z) and some pages even already use it for options (i.e. tldr grep: --{{context|before-context|after-context}}={{3}}). So I'd suggest, whenever there is a GNU style option, but the Unix style option is used by everybody, to use a syntax like this: {{--sync|-S}}

@CleanMachine1
Copy link
Member

From what I can tell, the unwritten rule is use the short if it is really common

for example From tldr git commit

  • Commit staged files to the repository with a message:
    git commit -m "message"

@pixelcmtd
Copy link
Member

@CleanMachine1 Are you sure about that? Because that would mean there is an unwritten rule that both you and marchersimon were not aware of less than a year ago. If it is a rule, let's at least write it down.

And I still don't think that this is the perfect solution, we should have a way of including the long form somehow.

@CleanMachine1
Copy link
Member

CleanMachine1 commented Apr 24, 2022

😄 I forgot the context of that but it was something to do with making the commands understandable rather than rememberable.

I think the current way we have is okay, which from what I can tell is use the long flags unless there is a valid reason not to

By adding to it such as {{--sync --refresh --sysupgrade|-Syu}}, it stops the user from being able to copy the commands directly which is a pretty nice feature, and to remove it is a little annoying.

@blueglyph
Copy link
Author

(About the context: I included the link in the 1st post for convenience).

I agree with @CleanMachine1 that the format {{--sync|-S}} is not practical; besides it lowers the readability.
On the other hand, having two lines as I suggested may lengthen the page when there are too many alternatives.

I'm not sure if the md syntax would allow both alternatives on the same line when it's short enough, as for ex:

sudo pacman --sync --refresh --sysupgrade or sudo pacman -Syu

By separating the format of 'or' naturally with the colours, if need be with brackets, or using '||' instead, I think it would remain clear.

Everyone uses pacman -Syu without remembering what any of that actually means

I think it touches a fundamental question.

If it is described above the command, the necessary information remains to associate the functionality to the command, even if it's not always clear which letter means what - especially when they change, like 'y'... There are other examples that help understand the letters. And many other commands only have the short form anyway.

Perhaps it depends on the purpose of tldr,

  • is it used as a refresher, for someone who knows the details and exactly what a command does?
  • is it used for someone who doesn't know about the command (but its name), and needs to perform an operation?

If that's the latter, all details must be added because we don't want someone to half-knowingly type sudo commands, but then we're back to the man pages. My understanding is that it's meant mainly for the former, I must update or look for a package but I'm not sure about the letters anymore because there are many combinations, and looking up the man pages takes a lot of time.

I'm about to use this command quite a few times, so maybe I don't want to type the long form, or maybe I memorize the short form more easily. Still, other people probably prefer the long form and it should remain. What is important is the description above, short enough to describe unambiguously what the command does.

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Apr 25, 2022

So I'd suggest, whenever there is a GNU style option, but the Unix style option is used by everybody, to use a syntax like this: {{--sync|-S}}

@pixelcmtd, I personally like it for simple commands. But what to do with separation by folders?

  • Linux: long options
  • OSx: short options
  • Common: most used options (long or short)

It already exists. Note that right now not all pages are duplicated to support long/short options.

Another question: what to prefer - joined single-letter (-ab) options or not (-a -b)? We have to mandate Tl;Dr writers to use one style and have to understand what is better suites for us. 😄

  • is it used for someone who doesn't know about the command (but its name), and needs to perform an operation?

Sometimes we can't provide comprehensive descriptions of commands because they for instance have too many defaults to list them explicitly or have complex syntax which can't be expressed easily via placeholders. For instance we can't at once describe Python syntax in 8 examples and mention CLI. But for sed/jq it's simpler: they are domain specific languages and we know what users need most often.

Simple commands (cd, csh, pwd, etc.) you can understand just from Tl;Dr pages. Everything depends of command complexity. In case of simple commands Tl;Dr is more like a help for newcomers but in other cases it's like a reminder.

@github-actions github-actions bot added the Stale label May 11, 2022
@pixelcmtd pixelcmtd added stalebot ignore decision A (possibly breaking) decision regarding tldr-pages content, structure, infrastructure, etc. and removed Stale labels Jun 1, 2022
@github-actions github-actions bot added the Stale label Jun 17, 2022
@pixelcmtd pixelcmtd removed the Stale label Jun 23, 2022
@YalandHong
Copy link

Related to #7702, #6246, #5092

@marchersimon
Copy link
Collaborator

Personally, I still like the solution I proposed in #6246. It works with all clients and doesn't make the example any longer. And if we only do this for very common pages there's also not a lot more effort to maintain this new convention.

@maverick1872
Copy link

I just wanted to chime in here and advocate for some means of including the short options alongside the long options. pacman -Syu is a great example as the short options don't match the long options. As such people who see something like 'just use pacman -Syu' may look at the tldr page to see if it's covered and what those options mean. Currently that information is not provided as no mention to the shorthand is given now.

As a intermediary solution that still supports copy-pasta while also providing the information necessary we could potentially do something like the following
sudo pacman --sync --refresh --sysupgrade (-Syu)
sudo pacman -Syu (--sync --refresh --sysupgrade)

My preference is the latter, less to copy and then the common variant is also by default in shell history.

@marchersimon
Copy link
Collaborator

I think this would be doable. But we would have to restrict this exception to only very few pages (like pacman). In most of the cases adding the short option would just make everything less readable. And I think that sudo pacman --sync --refresh --sysupgrade (-Syu) should be used, since the long options are the main part and the short options are just an addon.

@sbrl @navarroaxel @CleanMachine1 do you think we could make an exception for pacman (and maybe a very few others)?

@sbrl
Copy link
Member

sbrl commented Aug 2, 2022

As others have discussed the general rule has been that if a command is commonly used, we use short options on that page. There are many commands used in day-to-day terminal usage, and tldr-pages should reflect the version that people are most likely to use. The example of sudo pacman -Syu is a great one here. The tar page gives a good example of how these can be documented.

The pacman page was changed to long options in #6083 which seems to have passed me by, but had I noticed I would have raised this at the time.

@maverick1872
Copy link

I will say I think it's hard to define what is commonly used in general hence advocating for including shorthands as a default. While the tar implementation is a viable approach, that doesn't translate cleanly to the above pacman example, as -y === --refresh shares no letters in common. Hence the thought of including it in a parens block at the end of the command.

@jxu
Copy link
Collaborator

jxu commented Aug 21, 2022

I agree with defaulting to short options and the argument that tldr is for practical commands. The point of the command explanation is to explain the flags, so it is redundant with long options.

@github-actions github-actions bot added the Stale label Oct 6, 2022
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2023
@blueglyph
Copy link
Author

Sad to see this closed.

Out of curiosity, is that by lack of consensus? It seems that displaying two lines like the first example only got 6 upvotes and no downvotes so I don't understand why it shouldn't be adopted for some of the commands where practically all examples use the short format.

@jxu
Copy link
Collaborator

jxu commented Jan 5, 2023

It was closed automatically as stale by gh actions bot, which I disagree with on principle (it's not that old)

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Jan 5, 2023

There are standardized rules now when to use long and short options which I've proposed. You can check style guide for them. :) As «commonly used» is not a clear and hard measurable criteria I've decided to rely on option portability across different platforms to chose when to use a long option and when a short counterpart. I guess that long non portable options can be shown via shell commentary on the same string. It will not introduce a new page syntax and make all clients to support such new feature. :) But our official clients can optionally handle these commentaries in a such way that they are shown on a separate string in a format smth like that:

Note: there is --long == -s option available too.

@blueglyph
Copy link
Author

blueglyph commented Jan 5, 2023

There are standardized rules now when to use long and short options which I've proposed. You can check style guide for them. :)

@EmilySeville7cfg I see now, my database was simply not updated. Thanks for the style-guide update!

But I see this specific issue has been discussed by someone again from scratch in another issue (#8286) instead of continuing the discussion here, and that it finally ended up with short format only. Then this duplicate issue was closed instead of this one, so it's confusing.

I see the guide suggests either long or short format now, which one may find strange and arbitrary. It means that users don't see that pacman -y is the same as pacman --refresh, or that sudo --login is actually typed by everyone as sudo -i (I have never, ever used the long format for commands that I'm using all the time like sudo).

So it's a good step but ultimately I would have kept both short and long formats, I don't see why GNU commands and OS-specific commands should have a different treatment, to be honest.

It would be very easy to display each style on its own line like in the first post, and to implement a basic parsing with an option to see both formats or only one of them (for ex. from a command-line option or from an environment variable, like ls does). Tools without this parsing would display both lines for the few commands that feature them, which is not a problem. I would happily do the implementation as pull request for tealdeer and modify a couple of commands here as a demo.

I fear it's too late to restart this painful discussion though. 😉

@github-actions github-actions bot removed the Stale label Jan 6, 2023
@EmilyGraceSeville7cf
Copy link
Contributor

It would be very easy to display each style on its own line like in the first post, and to implement a basic parsing with an option to see both formats or only one of them (for ex. from a command-line option or from an environment variable, like ls does). Tools without this parsing would display both lines for the few commands that feature them, which is not a problem. I would happily do the implementation as pull request for tealdeer and modify a couple of commands here as a demo.

I agree, the best solution to provide both option's styles and give user a chance to select the preferred one.

@blueglyph
Copy link
Author

blueglyph commented Jan 7, 2023

I have modified tealdeer and the sudo tldr page to illustrate what I meant. Should I start a new discussion to give it more visibility?

Since I'm not the owner of this tool, I have forked the project and made a pre-release here (currently tagged "CODE-FILTER-RC1" in the "code-filter" branch):
https://github.com/blueglyph/tealdeer/releases

Assets also include

  • a Windows executable and a Manjaro/Arch binary. Otherwise, it's easy to build if you have the Rust toolchain (I can try to provide other binaries but no guarantee).
  • a modified sudo.md file to test the binary, located in tldr-pages\pages\common\sudo.md in the local cache, more on that below.

Let me know what you think. 😀 If that's all right, then I'll propose the change to tealdeer and I can update a few tldr pages here.

Proposed change

When there are "short" and "long" option format alternatives, they are (optionally) given on two consecutive lines, for example: (old format but I haven't seen any new format yet - the proposed change and its implementation work with both anyway)

- Launch the default shell with superuser privileges and run login-specific files (`.profile`, `.bash_profile`, etc.):

`sudo --login`
`sudo -l`

The filter compares two consecutive lines of example code. One must have more -- formats than the other, and the other must have more - formats than the one - the former will be considered as "long" and the latter as "short". It doesn't matter which of the "short" and "long" alternatives is given first. So it is very basic for the sake of speed, no regex expression, no trying to identify a command, only the criterion above.

All other cases won't be considered as alternatives and will always be displayed. Normally, there shouldn't be successive lines of codes so far, so I don't think there should be any conflict with the current pages.

Tool implementation

The modified tealdeer features a new command-line option and a new config options for the code filter:

  • short will only display the "short" format when possible (e.g. when there's an alternative)
  • long will only display the "long" format when possible
  • all will display both formats

The command-line option is prevalent. When it is not specified and there is no entry in the config file, the default is all.

Command-line:

    --option <FORMAT>        Option format in code examples [possible values: short, long, all]

Config file:

    [display]
    option_format = "long"

Test with pre-release

  • compile the binary if necessary, with cargo build -r
    • WARNING - this tool uses anyhow, which exposes a tooling bug since 1.0.62 and will likely fail to compile the first time with an error "error[E0554]: '#![feature]' may not be used on the stable release channel". If that happens, just clean and retry, with cargo clean, cargo build -r. See here for an explanation.
  • put the binary in the path
  • if it's the first time you launch this tool on your system, do a tldr --update to fetch the latest tldr pages
  • check where the tldr pages are cached: tldr --show-paths
  • replace the sudo.md file with the asset given in the pre-release, to test the filter feature or see how consecutive lines look
  • try tldr --option=all, tldr --option=long, tldr --option=short

I have duplicated a couple of options in the sudo page and changed one to the short format on purpose. I have also added a fake example at the end with a mix of long and short options to show that it can select the preferred "short" format despite -- options:

- Example with two options to showcase the filter feature:

`sudo --login --user={{user}}`
`sudo -l --user={{user}}`

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Jan 7, 2023

Let me know what you think. grinning If that's all right, then I'll propose the change to tealdeer and I can update a few tldr pages here.

I like this change. But I have another suggestion too now. :) I've created repo for formalizing CLI of all available commands though JSON schemas. It means that if we implement a proper CLI parser we will be able to replace short <-> long options based on user request as we will know what expect in some command CLI interface. But further more we will be able to validate commands and create linters for such tools like find.

BTW, I see an issue in your decision. It's not clearly defined for instance where long option ends: it's undefined which assignment style it uses: just space, equal sign or smth else. My way to solve this issue addresses this problem. :) Also, what if some option is not convertible to it's long or short counterpart? How do we know how to extract options to find their counterparts? What implications are done here? Note that such questions are only valid if a real CLI parser gonna to be written. If we just present short/long options on two separate lines we care about command correctness ourselves (but I prefer to rely on programs). 😄

If we would have a CLI parser we can optionally select which options to present as long and which as short, what assignment style to prefer and everything it automatically. :) For example always show -m for git commit but display long options for everything else.

@blueglyph
Copy link
Author

I like this change. But I have another suggestion too now. :) I've created repo for formalizing CLI of all available commands though JSON schemas. It means that if we implement a proper CLI parser we will be able to replace short <-> long options based on user request as we will know what expect in some command CLI interface. But further more we will be able to validate commands and create linters for such tools like find.

That's ... quite a change, sorry I missed that discussion or I wouldn't have bothered. It will solve several issues indeed, do you intend to put all the languages at the same place? Or in separate files?

I suppose it could take a while before all the pages are translated. From what I saw, they haven't been translated into the "new" syntax defined in RFC 958 yet. It also means a complete re-work of the existing tools.

So for the practicalities, what now, should I simply delete everything?

BTW, I see an issue in your decision. It's not clearly defined for instance where long option ends: it's undefined which assignment style it uses: just space, equal sign or smth else. My way to solve this issue addresses this problem. :)

I'm not sure I understand the problem. Do you mean there are long options that are sometimes specified with another syntax than --? The examples I've seen always followed this pattern. We're not talking about many changes, either, and if necessary we can simply agree to put the short format on the 1st line and the long format on the 2nd line.

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Jan 7, 2023

It will solve several issues indeed, do you intend to put all the languages at the same place? Or in separate files?

I intend to keep exactly the same file structure like in this repo for pages folder. Just one difference will be here: instead of .md files at the same places .yaml will be present. :)

So for the practicalities, what now, should I simply delete everything?

No, it's a good work. And until I've made everything ready to automate CLI checking we can use your solution. :) It's definitely better than just having just one thing shown (short or long options).

Do you mean there are long options that are sometimes specified with another syntax than --?

It's not clear what delimits option value and the option itself. Sometimes it's equal sign, sometimes it's space, sometimes it's smth else... I wanna universal solution to be able describe almost any CLI can be created.

We're not talking about many changes, either, and if necessary we can simply agree to put the short format on the 1st line and the long format on the 2nd line.

We should agree. :) Otherwise how do script quickly know what line to use to short short options or long ones? Can you create a PR changing CLIENT-SPECIFICATION to allow two lines for code example instead of one?

@blueglyph
Copy link
Author

I intend to keep exactly the same file structure like in this repo for pages folder. Just one difference will be here: instead of .md files at the same places .yaml will be present. :)

Oh I see. My mistake, I misunderstood what you meant by language-independent. 😄

No, it's a good work. And until I've made everything ready to automate CLI checking we can use your solution. :) It's definitely better than just having just one thing shown (short or long options).

I mean, I'm not convinced others would adopt it, even less if the format was supposed to change. But I suppose it can't hurt to modify a few pages and create a pull request, same with the tool. Have you already started working on other tools to support the JSON format, or do you know if someone else has?

It's not clear what delimits option value and the option itself. Sometimes it's equal sign, sometimes it's space, sometimes it's smth else... I wanna universal solution to be able describe almost any CLI can be created.

Ah, you mean the *.md format versus the *.json format, not specifically the little modification I suggested.

Agreed, it's not obvious. I suppose that options mostly begin with - or --, followed by a mix of a-zA-Z0-9_ and - characters. Then a space and optionally a value, or = and a value. It's a bit fuzzy. The obvious ambiguity that comes to mind is wc -l {{path/to/file}}: is the file attached to "-l", or is "-l" just a flag and the filename a general argument for the command. It's impossible to determine without knowing the command.

Too bad because a script could have pre-translated the markdown pages to JSON. I suppose it's still possible to do that to speed up the conversion, but someone has to make a verification pass.

We should agree. :) Otherwise how do script quickly know what line to use to short short options or long ones? Can you create a PR changing CLIENT-SPECIFICATION to allow two lines for code example instead of one?

I explained it above, it compares the number of "--" and "-" in both lines. Should we enforce 1st line long and 2nd line short or just let the tool find out? To be honest, enforcing it simplifies the code, but if someone makes a mistake it won't be detected (unless s/o provides a script to check).

Either is fine by me, we could simply wait to see if others chime in. I can do the PR, yes.

PS: I made a quick Python script to check and at the moment, no page has successive code lines. So at least there will be no conflict.

@blueglyph
Copy link
Author

Thanks for your comments, by the way!

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Jan 7, 2023

Should we enforce 1st line long and 2nd line short or just let the tool find out?

I suggest to enforce (and later to implement basic script check to ensure whether everything is okay).

PS: I made a quick Python script to check and at the moment, no page has successive code lines. So at least there will be no conflict.

Can you share it with me?

@blueglyph
Copy link
Author

PS: I made a quick Python script to check and at the moment, no page has successive code lines. So at least there will be no conflict.

Can you share it with me?

Sure. I had this one to show the successive lines of the pages I modified. It's quick and dirty and only works on the "old" syntax.

"""Looks for successive code lines in all *.md files (a code line begins with `)"""

import os
from os.path import join
from itertools import pairwise

for root, dirs, files in os.walk("."):
    for file in (fi for fi in files if fi.endswith(".md")):
        filename = join(root, file)
        with open(filename, encoding="utf8") as f:
            for a, b in pairwise(f.readlines()):
                if a.startswith('`') and b.startswith('`'):
                    print(f"{filename}:\n- {a}- {b}")
                    break

It doesn't print anything on the unmodified pages. It may be a good base to validate any file with long/short alternatives; I can do that later.
I have modified it to count the max number of successive lines and keep the file name:

mx = 0
for root, dirs, files in os.walk("."):
    for file in (fi for fi in files if fi.endswith(".md")):
        filename = join(root, file)
        count = 0
        with open(filename, encoding="utf8") as f:
            for line in f.readlines():
                if line.startswith("`"):
                    count += 1
                    if count > mx:
                        mx = count
                        mx_file = filename
                else:
                    count = 0
print(f"max = {mx} in file {mx_file}")

It returns 1.

@blueglyph
Copy link
Author

You need to be in tldr-main/pages to launch it, or you'll get false positives with the other *.md files at the top (which means I haven't verified the other languages).

@EmilyGraceSeville7cf
Copy link
Contributor

I'll check it tomorrow I guess. Thanks. :)

@blueglyph
Copy link
Author

You're welcome. 🙂
You can modify both scripts like that to launch from the top and look into all the pages* subdirectories:

from glob import glob

for page in glob("pages*"):
    print(f"processing {page}...")
    for root, dirs, files in os.walk(page):
    /* ... */

@blueglyph
Copy link
Author

blueglyph commented Jan 7, 2023

I realize that 2 consecutive lines are shown on the same line, in some markdown (not here but for ex. in IntelliJ plugin):

sudo pacman --sync --refresh --sysupgrade sudo pacman -Syu

Could that be a problem for some tools?

@EmilyGraceSeville7cf
Copy link
Contributor

sudo pacman --sync --refresh --sysupgrade sudo pacman -Syu

I guess it's just a render problem and should be addressed specifically with such problematic plugins.

@EmilyGraceSeville7cf
Copy link
Contributor

@blueglyph, here is my attempt to check the order of code examples (first one should have long options and the second one - short ones):

import os
from os.path import join
from itertools import pairwise
import re
from typing import Tuple, List, NewType

ShortOptions, LongOptions = NewType("ShortOptions", str), NewType("LongOptions", str)

def get_options(code) -> Tuple[List[ShortOptions], List[LongOptions]]:
    code = f" {code[1:-1]} "
    return (re.findall(r"\s+-([A-Za-z])\s+", code),
            re.findall(r"\s+--([A-Za-z][-A-Za-z0-9]+)\s+", code))

for root, directories, files in os.walk("."):
    for file in (filename for filename in files if filename.endswith(".md")):
        filename = join(root, file)
        with open(filename, encoding="utf8") as file:
            first_code_example = True
            for line in file.readlines():
                if line.startswith("`"):
                    line = line.rstrip('\n')
                    short, long = get_options(line.rstrip('\n')[1:-2])
                    stats = f"[short: {short}, long: {long}]"
                    if len(short) == 0 and len(long) == 0:
                        pass
                    elif len(short) > 0 and len(long) > 0:
                        print(f"{filename}: expected short or long options only in {line} {stats}")
                    elif first_code_example and (len(short) > 0) and (len(long) == 0):
                        print(f"{filename}: expected long options only in the first example {line} {stats}")
                    elif (not first_code_example) and (len(short) == 0) and (len(long) > 0):
                        print(f"{filename}: expected short options only in the second example {line} {stats}")
                    first_code_example = False
                else:
                    first_code_example = True
                    

@blueglyph
Copy link
Author

@EmilySeville7cfg Nice! I have a few suggestions, for what it's worth:

For the algorithm:

  • we should allow short options in "long" examples, because sometimes there may be no equivalent (ex: pacman -S --needed - needed has no short option and can only be used with -S; the long version is pacman --sync --needed). The reverse may be true too. That's why I compared the 2 lines instead (see code at the bottom)
  • using itertools.pairwise() could make your life easier, esp. given what I wrote above. It iterates through the lines and hands two lines at a time, so (line0, line1), (line1, line2), (line2, line3) and so on. => Only doing the comparison when there are a couple of code lines available, and using something similar to your boolean flag logic to make sure we don't see a couple of code lines in consecutive iterations (meaning: there must never be more than 2 consecutive lines of code)

And to speed up the code, are regex necessary? We don't really care about the name of the options, so isn't this enough?

long = line.count(" --")
short = line.count(" -") - long

Here's the algorithm I used; it's Rust but hopefully it's clear enough. the count of short and long are in prev for the previous line, and in curr for the current line:

        if prev.long < curr.long && prev.short > curr.short {
            return OptionFmtSeq::ShortThenLong;
        } else if prev.long > curr.long && prev.short < curr.short {
            return OptionFmtSeq::LongThenShort;
        } else {
            return OptionFmtSeq::Other;
        }

So in short, if we want "long" first, we want to see more "long" in the previous line, and more "short" in the current line. Just a suggestion, but I think it will be more flexible and still as robust.

PS: I see there's already a tldr-lint, but I'm not comfortable enough with Javascript to modify it. 😅 And it's not used in the GitHub workflow, that's strange, maybe it's too prone to false positives? Your Python script will do nicely in the workflow though.

@EmilyGraceSeville7cf
Copy link
Contributor

PS: I see there's already a tldr-lint, but I'm not comfortable enough with Javascript to modify it.

That's why I am going to narrow down list of used languages in TlDr while rewritting existing things to Python, Bash and Go (I don't like JS too). :)

@blueglyph
Copy link
Author

sudo pacman --sync --refresh --sysupgrade sudo pacman -Syu

I guess it's just a render problem and should be addressed specifically with such problematic plugins.

Maybe... I was just afraid of making the pages not back-compatible. If users just see two lines sometimes, it's fine, but if they see 2 examples on the same line it will be a mess. Mobs will rise. Heads will roll.
But you've been around for a while so you know best.

I have modified CLIENT-SPECIFICATION.md, style-guide.md and pacman.md. Can I ask for your opinion before making the pull request? I thought your guide was the perfect place for the rule (long first, etc), but should it be in the CLI spec? And let me know if it's understandable or just gibberish. 😉

https://github.com/blueglyph/tldr/commit/a7b535042107324e0a8c1987450706842050bbe9

@EmilyGraceSeville7cf
Copy link
Contributor

EmilyGraceSeville7cf commented Jan 8, 2023

Maybe... I was just afraid of making the pages not back-compatible.

If I would keep backward compatibility constantly now we had no such standardized rules. So sometimes we can sacrifice compatibility to enhance smth.

I have modified CLIENT-SPECIFICATION.md, style-guide.md and pacman.md. Can I ask for your opinion before making the pull request? I thought your guide was the perfect place for the rule (long first, etc), but should it be in the CLI spec? And let me know if it's understandable or just gibberish. wink

I like how it's written, please send PR here. :)

@blueglyph
Copy link
Author

I like how it's written, please send PR here. :)

Thanks, there you are.

I've also run both original and the new simplified RC2 tealdeer client on all pages to verify there was no regression. Just for the fun of it I have made a small but cleaner Python script for that. If you want, you can plug your code as a new test / function.
run_tldr_pages.zip

Feel free to use and modify the script as you wish if you find it useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision A (possibly breaking) decision regarding tldr-pages content, structure, infrastructure, etc.
Projects
None yet
Development

No branches or pull requests

9 participants