Skip to content

Commit

Permalink
overrides.jq: undo formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmodena committed Oct 24, 2024
1 parent efe45f5 commit 53c3f55
Showing 1 changed file with 32 additions and 32 deletions.
64 changes: 32 additions & 32 deletions modules/overrides.jq
Original file line number Diff line number Diff line change
@@ -1,42 +1,42 @@
# Convert entry value into array
def values ($value): if ($value | type) == "string" then [$value] else ($value // []) end;
def values($value): if ($value | type) == "string" then [$value] else ($value // []) end;

# State aliases
($old_state.overrides[$app_id] // {}) as $old
($old_state.overrides[$app_id] // {}) as $old
| ($new_state.overrides[$app_id] // {}) as $new

# Map sections that exist in either active or new state (ignore old)
| $active + $new | keys | map (
. as $section | {"section_key": $section, "section_value": (

# Map entries that exist in either active or new state (ignore old)
($active[$section] // {}) + ($new[$section] // {}) | keys | map (
. as $entry | { "entry_key": $entry, "entry_value": (

# Entry value aliases
$active[$section][$entry] as $active_value
| $new[$section][$entry] as $new_value
| $old[$section][$entry] as $old_value

# Use new value if it is a string
| if ($new_value | type) == "string" then $new_value
else
# Otherwise remove old values from the active ones, and add the new ones
values($active_value) - values($old_value) + values($new_value)

# Remove empty arrays and duplicate values
| select(. != []) | unique

# Convert array into Flatpak string array format
| join(";")
end
)}
)

# Remove empty arrays
| select(. != [])
)}
)[]
. as $section | {"section_key": $section, "section_value": (

# Map entries that exist in either active or new state (ignore old)
($active[$section] // {}) + ($new[$section] // {}) | keys | map (
. as $entry | { "entry_key": $entry, "entry_value": (

# Entry value aliases
$active[$section][$entry] as $active_value
| $new[$section][$entry] as $new_value
| $old[$section][$entry] as $old_value

# Use new value if it is a string
| if ($new_value | type) == "string" then $new_value
else
# Otherwise remove old values from the active ones, and add the new ones
values($active_value) - values($old_value) + values($new_value)

# Remove empty arrays and duplicate values
| select(. != []) | unique
# Convert array into Flatpak string array format
| join(";")
end
)}
)

# Remove empty arrays
| select(. != [])
)}
)[]

# Generate the final overrides file
| "[\(.section_key)]", (.section_value[] | "\(.entry_key)=\(.entry_value)"), ""

0 comments on commit 53c3f55

Please sign in to comment.