Skip to content

Instantly share code, notes, and snippets.

@flisboac
Last active January 3, 2023 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flisboac/569acddb9ac0a2b19d46c7c4aa5e739b to your computer and use it in GitHub Desktop.
Save flisboac/569acddb9ac0a2b19d46c7c4aa5e739b to your computer and use it in GitHub Desktop.
simple state function to perform join with json serialization
{
"StartAt": "CreateCliParams",
"States": {
"CreateCliParams": {
"Type": "Pass",
"Next": "CreateCliParams_ifJoinParams",
"Parameters": {
"CliParameterSeparator.$": "$.CliParameterSeparator",
"CliCurrentParameterSeparator": "",
"CliParameters.$": "$.CliParameters[*][*]",
"CliParametersBuffer": "",
"CliParameterIndex.$": "States.ArrayLength($.CliParameters[*][*])"
}
},
"CreateCliParams_ifJoinParams": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.CliParameterIndex",
"NumericGreaterThan": 0,
"Next": "CreateCliParams_thenJoinParams"
}
],
"Default": "ExecuteCliCommand"
},
"CreateCliParams_thenJoinParams": {
"Type": "Pass",
"Next": "CreateCliParams_ifJoinParams",
"Parameters": {
"CliParameterSeparator.$": "$.CliParameterSeparator",
"CliCurrentParameterSeparator.$": "$.CliParameterSeparator",
"CliParameters.$": "$.CliParameters[1:]",
"CliParametersBuffer.$": "States.Format('{}{}{}', $.CliParametersBuffer, $.CliCurrentParameterSeparator, States.JsonToString($.CliParameters[0]))",
"CliParameterIndex.$": "States.MathAdd($.CliParameterIndex, -1)"
}
},
"ExecuteCliCommand": {
"Type": "Pass",
"Next": "End",
"Parameters": {
"CliCommand.$": "States.Format('bash -c {}', States.JsonToString($.CliParametersBuffer))"
}
},
"End": {
"Type": "Succeed"
}
}
}
{
"CliParameters": [["ls"], ["-la", "-w", 1], ["\".\""]],
"CliParameterSeparator": " "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment