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

Remove JUST_HELP_SEPARATOR #168

Open
andyneff opened this issue Aug 22, 2019 · 2 comments
Open

Remove JUST_HELP_SEPARATOR #168

andyneff opened this issue Aug 22, 2019 · 2 comments

Comments

@andyneff
Copy link
Member

Currently, _just_commands_from_file parses bash files to get the targets and help in one go and stored in an array. From here on all of just's logic uses this JUST_HELP_SEPARATOR and parses this one array accordingly, adding addition complicated logic that is unneeded.

I propose a new pattern that instead of setting parsed_help_a, it instead sets two arrays right away, parsed_commands_a and parsed_help_a, thus simplifying the rest of just

The awk code could even be modified (add to the end) to do something like:

Before:

target1 #@#Target1 help
target2 #@#Target2 help

After

target1
Target1 help
target2
Target2 help

By adding s|#@#(.*)|\n\1| in non-global, which would theoretically allow for a comment to contain #@# but not a target.

@andyneff andyneff added this to the just 0.2.3 milestone Aug 22, 2019
andyneff added a commit that referenced this issue Aug 22, 2019
- Replaced by #168

Signed-off-by: Andy Neff <[email protected]>
@andyneff
Copy link
Member Author

Proposed _just_commands_from_file

sed -nE ':combine
            # These next 5 lines combine lines ending in \ and remove leading spaces on next line
            /\\$/{
              # Read and append next line
              N
              # If the pattern buffer matches the case pattern, ends in a
              # \ and the comment continues on the next line, then combine
              /^ *#? *[ ?*_0-9|a-zA-Z{}"'"'"'-]*\) *#.*\\\n *#/{
                # Combine the two lines, removing the extra #, replacing it
                # with a single space
                s| *\\\n *# *| |
                t combine
              }
              s|\\\n *||''
              t combine
            }
            # Remove tabs
            s|\t+| |g
            s|^ *#? *([ ?*_0-9|a-zA-Z{}"'"'"'-]*[?*_0-9|a-zA-Z{}"'"'"'-]) *\) *# *(.*)|\1\t\2|
            # If there is a match, process it
            t process
            # Else do not even print it. This replaces a grep
            b noprint
            :process
            # Remove trailing spaces
            s| +$||
            :processloop
            # Converts aaa|bbb|ccc @#@ blah to aaa @#@ blah\nbbb @#@ blah\n...
            s/\|(.*\t(.*))/\t\2'$'\\\n''\1/
            # Continue processing until no matches
            t processloop
            # Remove quotes
            s/^["'"'"']([^\n]*)["'"'"']\t/\1\t/
            s/\n["'"'"']([^\n]*)["'"'"']\t/\n\1\t/g
            # Convert output to two lines per target
            s/\t/\n/g
            p
            :noprint' {files}

@andyneff
Copy link
Member Author

The new just help (after https://github.com/VisionSystemsInc/vsi_common/tree/just_spaces) will print help by by plugin instead of as one long list, and lists like parsed_commands_a will only be used for tab complete and nothing else. So this may or may not change what needs to happen here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant