javaproperties-cli — Command-line manipulation of Java .properties files

javaproperties-cli is a wrapper around the javaproperties package (from which it was split off) that provides programs for basic command-line manipulation of Java .properties files, including getting, setting, & deleting values and converting to & from JSON.

Currently, the programs only support .properties files in the simple line-oriented format, not the XML variant.

javaproperties

NAME

javaproperties — Basic manipulation of Java .properties files

SYNOPSIS

javaproperties get    [<OPTIONS>] <file> <key> ...
javaproperties select [<OPTIONS>] <file> <key> ...
javaproperties set    [<OPTIONS>] <file> <key> <value>
javaproperties delete [<OPTIONS>] <file> <key> ...
javaproperties format [<OPTIONS>] [<file>]

get

javaproperties get [<OPTIONS>] <file> <key> ...

Print out the values of the given keys in the given .properties file. Each value is printed out on a separate line with escape sequences interpolated.

If you want the output to also be in .properties format, see select.

Options

-d <value>, --default-value <value>

Default value for undefined keys. If this option is not specified, keys requested on the command line that are not defined in either the main .properties file or the --defaults file will cause a warning to be printed to stderr and the command to exit with a failure status.

-D <file>, --defaults <file>

.properties file of default values. If this option is specified, keys requested on the command line that are not defined in the main .properties file will be looked up in this file.

-e, --escaped

Parse the keys and default value specified on the command line for .properties-style escape sequences (specifically, those supported by javaproperties.unescape)

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input file(s); default value: iso-8859-1 (a.k.a. Latin-1). Output always uses the locale’s encoding.

select

javaproperties select [<OPTIONS>] <file> <key> ...

Print out the key-value entries in the given .properties file for the given keys. The output is in .properties format, reformatted as though by format.

Options

-d <value>, --default-value <value>

Default value for undefined keys. If this option is not specified, keys requested on the command line that are not defined in either the main .properties file or the --defaults file will cause a warning to be printed to stderr and the command to exit with a failure status.

-D <file>, --defaults <file>

.properties file of default values. If this option is specified, keys requested on the command line that are not defined in the main .properties file will be looked up in this file.

-e, --escaped

Parse the keys and default value specified on the command line for .properties-style escape sequences (specifically, those supported by javaproperties.unescape)

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input and output files; default value: iso-8859-1 (a.k.a. Latin-1)

-o <file>, --outfile <file>

Write output to this file instead of standard output

-s <sep>, --separator <sep>

Use <sep> as the key-value separator in the output; default value: =

set

javaproperties set [<OPTIONS>] <file> <key> <value>

Set the value of <key> in the .properties file <file> to <value> and output the results. The other entries in the file (including comments, possibly not including the timestamp; see below) will be left as-is.

Options

-e, --escaped

Parse <key> and <value> for .properties-style escape sequences (specifically, those supported by javaproperties.unescape)

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input and output files; default value: iso-8859-1 (a.k.a. Latin-1)

-o <file>, --outfile <file>

Write output to this file instead of standard output

-s <sep>, --separator <sep>

Separate <key> and <value> in the output with <sep>; default value: =

-T, --preserve-timestamp

Do not modify the timestamp in the .properties file. By default, if a timestamp is found, it is updated to the current time, even if the rest of the file is unchanged.

delete

javaproperties delete [<OPTIONS>] <file> <key> ...

Remove all entries for the given keys from the given .properties file and output the results. The other entries in the file (including comments, possibly not including the timestamp; see below) will be left as-is.

Options

-e, --escaped

Parse the keys specified on the command line for .properties-style escape sequences (specifically, those supported by javaproperties.unescape)

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input and output files; default value: iso-8859-1 (a.k.a. Latin-1)

-o <file>, --outfile <file>

Write output to this file instead of standard output

-T, --preserve-timestamp

Do not modify the timestamp in the .properties file. By default, if a timestamp is found, it is updated to the current time, even if the rest of the file is unchanged.

format

javaproperties format [<OPTIONS>] [<file>]

Normalize the formatting of the given .properties file (or standard input if no file is given) and output the results. All comments, excess whitespace, invalid escapes, and duplicate keys are removed, and the entries are sorted and converted to ASCII with javaproperties.escape.

Options

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input and output files; default value: iso-8859-1 (a.k.a. Latin-1)

-o <file>, --outfile <file>

Write output to this file instead of standard output

-s <sep>, --separator <sep>

Use <sep> as the key-value separator in the output; default value: =

json2properties

NAME

json2properties — Convert a JSON object to a Java .properties file

SYNOPSIS

json2properties [<OPTIONS>] [<infile> [<outfile>]]

DESCRIPTION

Convert a JSON file infile to a .properties file and write the results to outfile. If not specified, infile and outfile default to sys.stdin and sys.stdout, respectively.

The JSON document must be an object with scalar (i.e., string, numeric, boolean, and/or null) values; anything else will result in an error.

Output is sorted by key, and numeric, boolean, & null values are output using their JSON representations; e.g., the input:

{
    "yes": true,
    "no": "false",
    "nothing": null
}

becomes:

#Mon Sep 26 18:57:44 UTC 2016
no=false
nothing=null
yes=true

OPTIONS

-E <encoding>, --encoding <encoding>

Use <encoding> as the output encoding; default value: iso-8859-1 (a.k.a. Latin-1). (As all output is currently always pure ASCII, this option is not very useful, but there are plans to make it useful.)

-s <sep>, --separator <sep>

Use <sep> as the key-value separator in the output; default value: =

properties2json

NAME

properties2json — Convert a Java .properties file to JSON

SYNOPSIS

properties2json [<OPTIONS>] [<infile> [<outfile>]]

DESCRIPTION

Convert a .properties file infile to a JSON object and write the results to outfile. If not specified, infile and outfile default to sys.stdin and sys.stdout, respectively.

OPTIONS

-E <encoding>, --encoding <encoding>

Specifies the encoding of the input file; default value: iso-8859-1 (a.k.a. Latin-1)

Indices and tables