Skip to content

rework if statement generation #1113

@Tirito6626

Description

@Tirito6626

current if-block logic is only based on comparing the exit code of the command inside arithmetic block:

if category == "server":

output:

if [ "$([ "_${category_48}" != "_server" ]; echo $?)" != 0 ]; then

not only is it not logical for output readability but also expensive in terms of power and time, by using subshells to capture the exit code.

the example above can be simplied to just:

if [ "${category_48}" = "server" ]; then

i know it's most likely made for reliable comparison with nesting and without the need to make the if logic more complicated (by e.g. comparing if condition types)

this also includes stuff like failed:

Image

can be simplified to just

if ! systemctl stop "${server_service_157}" 2>/dev/shm/.mirage_error_catch; then

if failed doesn't include any variable to save status into, but it's rather a bad example since status() still has to store it somehow

my biggest concern is having multiple conditions:

Image

apart from being very long, it contains two subshells inside arithmetic block, which is then tested with is not zero, which makes it harder to debug the source code and understand the logic

Metadata

Metadata

Assignees

Labels

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions