pkg icon indicating copy to clipboard operation
pkg copied to clipboard

--raw-format is broken when multiple packages are supplied

Open dch opened this issue 11 months ago • 3 comments

pkg version: pkg-1.21.3, json_verify comes from devel/yajl

$ pkg info --raw --raw-format json pkg | json_verify
JSON is valid
$ pkg info --raw --raw-format json pkg bash | json_verify
parse error: trailing garbage
                                        {     "name": "pkg",     "orig
                     (right here) ------^
JSON is invalid

This is because pkg info .. $THING returns a JSON object, but pkg info .. $THING1 $THING2 returns 2 JSON objects, separately:

...
}{ <---------------------------- invalid JSON
    "name": "bash",
    "origin": "shells/bash",
...

One possible solution is to wrap multiple packages in an array, and add a , separator.

Also, --raw-format requires --raw, perhaps set --raw flag if --raw-format is already found on command line.

dch avatar Jan 22 '25 19:01 dch

Also, --raw-format requires --raw, perhaps set --raw flag if --raw-format is already found on command line.

This should be default behavior.

The pkg-info man page makes no mention of --raw being required to use --raw-format and further makes it seem like it's not required.

     pkg info [--{annotations,provided-shlibs,required-shlibs}]
              [--{pkg-message,dependencies,full,comment,list-files}]
              [--{quiet,prefix,raw,required-by,size}] --file pkg-file
              [--raw-format format]

To a casual reader, it would appear that pkg info --raw-format json is a valid command.

rdnn avatar Mar 14 '25 18:03 rdnn

From the synopsis etc. it seems to me that --raw-format is an option only if --raw is specified for a single file:

Image

The relevant lines, without the formatting that's currently seen at https://man.freebsd.org/cgi/man.cgi?query=pkg-info&sektion=8&manpath=freebsd-ports:

pkg info [--{annotations,provided-shlibs,required-shlibs}] [--{pkg-message,dependencies,full,comment,list-files}] [--{quiet,prefix,raw,required-by,size}] --file pkg-file [--raw-format format]

--raw-format format Choose the format of the raw output. The format can be: ucl (default), json, json-compact, yaml.

Examples

Without opting for -R (--raw):

grahamperrin:/usr/local/poudriere/data/packages/current-default/.latest/All % pkg info -A --file ./ark-24.12.3_1.pkg
ark-24.12.3_1:
        build_timestamp: 2025-03-12T23:59:06+00:00
        ports_top_git_hash: 36031245380
        ports_top_checkout_unclean: yes
        port_git_hash  : 68866fcca48
        port_checkout_unclean: no
        built_by       : poudriere-git-3.4.99.20250209
        cpe            : cpe:2.3:a:ark:ark:24.12.3:::::freebsd15:x64:1
        FreeBSD_version: 1500034
grahamperrin:/usr/local/poudriere/data/packages/current-default/.latest/All %

JSON:

}grahamperrin:/usr/local/poudriere/data/packages/current-default/.latest/All % pkg info -R --file ./pkg_tree-1.1_6.pk --raw-format json
{
    "name": "pkg_tree",
    "origin": "ports-mgmt/pkg_tree",
    "version": "1.1_6",
    "comment": "Get a 'graphical' tree-overview of installed packages",
    "maintainer": "[email protected]",
    "www": "https://www.mavetju.org/unix/general.php",
    "abi": "FreeBSD:15:*",
    "arch": "freebsd:15:*",
    "prefix": "/usr/local",
    "flatsize": 7006,
    "licenselogic": "single",
    "licenses": [
        "BSD2CLAUSE"
    ],
    "desc": "Get a 'graphical' tree-overview of installed packages\n\nGenerates a ascii-art-graphical tree of packages and their dependancies.\nFor example for setxkbmap and xkbcomp\n\n      [~] edwin@k7>pkg_tree 'xkb[cm]'\n      setxkbmap-1.0.4\n      |\\__ kbproto-1.0.3\n      |\\__ pkg-config-0.23_1\n      |\\__ xproto-7.0.10_1\n      |\\__ libXau-1.0.3_2\n      |\\__ libXdmcp-1.0.2_1\n      |\\__ libX11-1.1.3_1,1\n       \\__ libxkbfile-1.0.4\n      xkbcomp-1.0.3\n      |\\__ kbproto-1.0.3\n      |\\__ pkg-config-0.23_1\n      |\\__ xproto-7.0.10_1\n      |\\__ libXau-1.0.3_2\n      |\\__ libXdmcp-1.0.2_1\n      |\\__ libX11-1.1.3_1,1\n       \\__ libxkbfile-1.0.4",
    "deps": {
        "perl5": {
            "origin": "lang/perl5.36",
            "version": "5.36.3_2"
        }
    },
    "categories": [
        "ports-mgmt"
    ],
    "annotations": {
        "build_timestamp": "2025-03-14T22:44:12+00:00",
        "ports_top_git_hash": "8735b54cc2c",
        "ports_top_checkout_unclean": "yes",
        "port_git_hash": "83edd06e2af",
        "port_checkout_unclean": "no",
        "built_by": "poudriere-git-3.4.99.20250209"
    },
    "files": {
        "/usr/local/bin/pkg_tree": "1$8146b35b74cc90e5279ca46a71ec51887a4f1b905db8806a3168e96789a2836c",
        "/usr/local/share/man/man7/pkg_tree.7.gz": "1$d9ff140ba327cb845d34ecb14f3d81db7a7407ccdc3e83799fae4f7c9a1cc7c0"
    }
}grahamperrin:/usr/local/poudriere/data/packages/current-default/.latest/All % 

grahamperrin avatar Mar 14 '25 22:03 grahamperrin