add preservation of comment lines#20
Draft
wififreedom wants to merge 2 commits intoopenwrt:masterfrom
Draft
Conversation
Member
|
You'll need to look into the submission guidelines regarding commit formatting, etc. |
Author
|
I will rebase with a proper commit message once I'm satisfied. I'm interested in early reactions if this feature is even desirable. |
Author
|
Tests written. |
Author
|
The shunit2 test is broken, does not fail if one of the subtests fails, because exit code 1 is not propagated. In tests/shunit2/tests.sh: should be: See #21 |
Features:
- uci now preserves comments in the existing config file for unaffected elements
when executing one of uci commands 'add', 'delete', 'set', 'add_list', and
'del_list'. For example:
# comment before config line 1 is preserved
# comment before config line 2 is preserved
config interface 'myinterface' # comment after config is preserved
# comment before option line 1 is preserved
# comment before option line 2 is preserved
option myoption 'myvalue' # comment after option is preserved
# this comment after all config/option/list lines is not preserved
- Commands 'set' and 'add_list' now support setting comment lines
before and a comment after the config/option line. For example:
uci set "dhcp.lan=dhcp## comment after: config dhcp 'lan'"
uci set "dhcp.lan.interface=lan## comment after: option interface 'lan'"
uci add_list "dhcp.lan.ra_flags=managed_config## line1\\n#line 2\\n#i after'"
results in:
config dhcp 'lan' # comment after: config dhcp 'lan'
option interface 'lan' # comment after: option interface 'lan'
# line 1
#line 2
list ra_flags 'managed_config' # after
- Command 'import' now also imports comments from the imported file into the
config file.
- Command 'output' now also exports comments from the config file to the
export result file.
- Comment lines are auto-indented when preserved.
Limitations:
- Comments at the end of the file are not preserved
Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
c1e751f to
075d2cb
Compare
Author
|
Additions i could implement:
|
92f0747 to
bf0a598
Compare
Command 'get <config>.<section>##' prints escaped comment associated with the section. Command 'get <config>.<section>.<option>##' prints escaped comment associated with the option. Signed-off-by: Bastiaan Stougie <wififreedom2026@protonmail.com>
bf0a598 to
a84cbcb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've implemented preservation of comments in the existing config file when doing one of uci commands 'add', 'delete', 'set', 'add_list', 'del_list', 'import' and 'export'.
Both comment lines before a non-comment (config/option/list) line and comments at the end of a non-comment line are preserved with the non-comment line. For example:
uci command line commands 'set' (for adding
configlines andoptionlines) and 'add_list' (for addinglistlines) now also support setting and updating comment lines before and a comment after the config/option/list line. For example:results in:
Comment lines are auto-indented when preserved.
Limitations: