Skip to content

Add builtin to output to file #3153

@myaaaaaaaaa

Description

@myaaaaaaaaa

I would like to propose a new builtin, say output_file("filename"; "contents"), which copies its input to its output while saving its arguments as a file. It's similar in principle to the debug builtin.

If --sandbox is specified, it will simply output the filename to stderr, essentially acting as a dry run.

Having this builtin would make it less awkward to split json files. See below for some workarounds that are currently required:

Proposed semantics:

# sample script
to_entries[] | output_file(.key; .value) | .key

# stdin
{
	"a.txt": "string\nstring",
	"b/c.txt": "invalid",
	"d.json": {
		"e": 10
	}
}

# stdout
"a.txt"
"b/c.txt"
"d.json"

# stderr
b/c.txt: No such file or directory


# a.txt
string
string

# d.json
{"e":10}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions