Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions tests/acceptance/plucked.sub.cf
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ body contain in_dir_shell(dir)
# ```
{
chdir => "$(dir)";
useshell => "true";

# canonical "useshell" but this is backwards-compatible
useshell => "true";
}

body contain in_shell
Expand All @@ -79,9 +79,8 @@ body contain in_shell
# contain => in_shell;
# ```
{
useshell => "true";

# canonical "useshell" but this is backwards-compatible
useshell => "true";
}

body contain in_shell_bg
Expand All @@ -90,9 +89,8 @@ body contain in_shell_bg
# parser strictness enhancements. Backgrounding is handeled by the body action
# background attribute.
{
useshell => "true";

# canonical "useshell" but this is backwards-compatible
useshell => "true";
}

body contain in_shell_and_silent
Expand All @@ -107,9 +105,8 @@ body contain in_shell_and_silent
# comment => "Silently run command in shell";
# ```
{
useshell => "true";

# canonical "useshell" but this is backwards-compatible
useshell => "true";
no_output => "true";
}

Expand All @@ -126,9 +123,8 @@ body contain in_dir_shell_and_silent(dir)
# comment => "Silently run command in shell";
# ```
{
useshell => "true";

# canonical "useshell" but this is backwards-compatible
useshell => "true";
no_output => "true";
chdir => "$(dir)";
}
Expand Down Expand Up @@ -752,10 +748,18 @@ bundle edit_line manage_variable_values_ini(tab, sectionName)
{
vars:
"index" slist => getindices("$(tab)[$(sectionName)]");
"_escaped_section" string => escape("$(sectionName)");

classes:
"section_$(sectionName)_exists"
expression => regline("^\[$(_escaped_section)\]", "$(edit.filename)"),
if => fileexists("$(edit.filename)"),
comment => "Check if the section header already exists in the file";

delete_lines:
".*"
select_region => INI_section(escape("$(sectionName)")),
if => canonify("section_$(sectionName)_exists"),
comment => "Remove all entries in the region so there are no extra entries";

insert_lines:
Expand All @@ -764,7 +768,12 @@ bundle edit_line manage_variable_values_ini(tab, sectionName)
comment => "Insert lines";

"$(index)=$($(tab)[$(sectionName)][$(index)])"
select_region => INI_section(escape("$(sectionName)"));
select_region => INI_section(escape("$(sectionName)")),
if => canonify("section_$(sectionName)_exists");

"$(index)=$($(tab)[$(sectionName)][$(index)])"
location => after("^\[$(_escaped_section)\]"),
if => not(canonify("section_$(sectionName)_exists"));
}

bundle edit_line set_variable_values_ini(tab, sectionName)
Expand All @@ -786,18 +795,26 @@ bundle edit_line set_variable_values_ini(tab, sectionName)

# Be careful if the index string contains funny chars
"cindex[$(index)]" string => canonify("$(index)");
"_escaped_section" string => escape("$(sectionName)");

classes:
"edit_$(cindex[$(index)])"
not => strcmp("$($(tab)[$(sectionName)][$(index)])", "dontchange"),
comment => "Create conditions to make changes";

"section_$(sectionName)_exists"
expression => regline("^\[$(_escaped_section)\]", "$(edit.filename)"),
if => fileexists("$(edit.filename)"),
comment => "Check if the section header already exists in the file";

field_edits:
# If the line is there, but commented out, first uncomment it
"#+\s*$(index)\s*=.*"
select_region => INI_section(escape("$(sectionName)")),
edit_field => col("\s*=\s*", "1", "$(index)", "set"),
if => "edit_$(cindex[$(index)])";
if => and(
"edit_$(cindex[$(index)])", canonify("section_$(sectionName)_exists")
);

# match a line starting like the key something
"\s*$(index)\s*=.*"
Expand All @@ -808,7 +825,9 @@ bundle edit_line set_variable_values_ini(tab, sectionName)
classes => results(
"bundle", "set_variable_values_ini_not_$(cindex[$(index)])"
),
if => "edit_$(cindex[$(index)])";
if => and(
"edit_$(cindex[$(index)])", canonify("section_$(sectionName)_exists")
);

insert_lines:
"[$(sectionName)]"
Expand All @@ -817,7 +836,20 @@ bundle edit_line set_variable_values_ini(tab, sectionName)

"$(index)=$($(tab)[$(sectionName)][$(index)])"
select_region => INI_section(escape("$(sectionName)")),
if => "!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired).edit_$(cindex[$(index)])";
if => and(
"!(set_variable_values_ini_not_$(cindex[$(index)])_kept|set_variable_values_ini_not_$(cindex[$(index)])_repaired)",
"edit_$(cindex[$(index)])",
canonify("section_$(sectionName)_exists")
),
handle => "insert_key_in_existing_section_$(sectionName)_$(cindex[$(index)])";

"$(index)=$($(tab)[$(sectionName)][$(index)])"
location => after("^\[$(_escaped_section)\]"),
if => and(
"edit_$(cindex[$(index)])",
not(canonify("section_$(sectionName)_exists"))
),
handle => "insert_key_in_new_section_$(sectionName)_$(cindex[$(index)])";
}

bundle edit_line insert_ini_section(name, config)
Expand Down
Loading