SimonButtazzi / node-red-contrib-boolean-parser

MIT License
1 stars 1 forks source link

support for exit code (different from invert logic) #3

Open YAMLcase opened 1 year ago

YAMLcase commented 1 year ago

exit codes from the exec node should be treated as:

inverting the logic as with #1 is a decent workaround, but not sufficient because other inputs, true, false get inverted.

Probably the best way is to add a new input handler for payload.code: int, but I'm not sure how difficult this would be compared to the node providing a new option for "invert int only" and having the user change input field to msg.payload.code.

Below is an export of my test bed using the linux commands true and false:

image

[
    {
        "id": "71e415a7afce0d70",
        "type": "exec",
        "z": "ac5d738a04ab6a0e",
        "command": "false",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 330,
        "y": 200,
        "wires": [
            [],
            [],
            [
                "cde9d7deeea061e0",
                "4a4f07641695f8a5"
            ]
        ]
    },
    {
        "id": "3d79b461ea9591df",
        "type": "inject",
        "z": "ac5d738a04ab6a0e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "71e415a7afce0d70"
            ]
        ]
    },
    {
        "id": "f6b9d8d7079a563e",
        "type": "exec",
        "z": "ac5d738a04ab6a0e",
        "command": "true",
        "addpay": "",
        "append": "",
        "useSpawn": "false",
        "timer": "",
        "winHide": false,
        "oldrc": false,
        "name": "",
        "x": 330,
        "y": 140,
        "wires": [
            [],
            [],
            [
                "cde9d7deeea061e0",
                "03d8abafb3074b97"
            ]
        ]
    },
    {
        "id": "900fdde1e9cd8f1e",
        "type": "inject",
        "z": "ac5d738a04ab6a0e",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 140,
        "wires": [
            [
                "f6b9d8d7079a563e"
            ]
        ]
    },
    {
        "id": "cde9d7deeea061e0",
        "type": "bool",
        "z": "ac5d738a04ab6a0e",
        "name": "bool(exitcode)",
        "outputs": 3,
        "inputField": "payload.code",
        "outputField": "payload",
        "outputFormat": "bool",
        "handleNull": "null",
        "invert": false,
        "strict": false,
        "x": 540,
        "y": 340,
        "wires": [
            [
                "03d8abafb3074b97"
            ],
            [
                "4a4f07641695f8a5"
            ],
            [
                "333c9fddd0fdb27f"
            ]
        ]
    },
    {
        "id": "03d8abafb3074b97",
        "type": "debug",
        "z": "ac5d738a04ab6a0e",
        "name": "should be true",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 300,
        "wires": []
    },
    {
        "id": "4a4f07641695f8a5",
        "type": "debug",
        "z": "ac5d738a04ab6a0e",
        "name": "should be false",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 360,
        "wires": []
    },
    {
        "id": "333c9fddd0fdb27f",
        "type": "debug",
        "z": "ac5d738a04ab6a0e",
        "name": "should be null",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 900,
        "y": 420,
        "wires": []
    },
    {
        "id": "8a13cf28e2beb15b",
        "type": "inject",
        "z": "ac5d738a04ab6a0e",
        "name": "msg.payload.code: true",
        "props": [
            {
                "p": "payload.code",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 280,
        "y": 520,
        "wires": [
            [
                "cde9d7deeea061e0",
                "03d8abafb3074b97"
            ]
        ]
    },
    {
        "id": "41f8fe160b55901a",
        "type": "inject",
        "z": "ac5d738a04ab6a0e",
        "name": "msg.payload.code: null",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 300,
        "y": 640,
        "wires": [
            [
                "cde9d7deeea061e0",
                "333c9fddd0fdb27f"
            ]
        ]
    },
    {
        "id": "183b09e92ebd3b81",
        "type": "inject",
        "z": "ac5d738a04ab6a0e",
        "name": "msg.payload.code: false",
        "props": [
            {
                "p": "payload.code",
                "v": "false",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 290,
        "y": 580,
        "wires": [
            [
                "cde9d7deeea061e0",
                "4a4f07641695f8a5"
            ]
        ]
    }
]
SimonButtazzi commented 1 year ago

Hi, thanks for the contribution.

Maybe I'll add some docs in future to make this feature more transparen/present.

SimonButtazzi commented 1 year ago

Feature is included in v1.4.5

SimonButtazzi commented 1 year ago

@YAMLcase if you like feel free to leave a rating at: https://flows.nodered.org/node/node-red-contrib-boolean-parser