Code Monkey home page Code Monkey logo

uclcmd's Introduction

uclcmd

Command line tool for working with UCL config files

Designed to be somewhat compatible with jq by implementing a very similar syntax: .object.object.arrayindex|command instead of jq's .object.object[arrayindex]|command

Although uclcmd commands are not actually 'piped' and only the 'each' command can be stacked. Running other commands just runs them sequentially

uclcmd currently targets the master branch of vstakhov/libucl, as some used features are not available in an existing release.

uclcmd's People

Contributors

allanjude avatar xmj avatar amdmi3 avatar savagedlight avatar igalic avatar

Stargazers

Kelly Thomas Kline avatar Pouria Mousavizadeh Tehrani avatar Anderson Torres avatar Pat Maddox avatar ngortheone avatar frankfanslc avatar Vladimir Botka avatar Charles avatar Linz avatar Roi Mallo avatar  avatar Alan D. Salewski avatar Richard Bowden avatar Shubh gupta avatar Tobias Bradtke avatar Satyen Rai avatar  avatar Hideaki Igarashi avatar Shingo Onobori avatar Fredrik Larsen avatar Uffe Jakobsen avatar Matt Singletary avatar Brandon Schneider avatar  avatar  avatar Trent avatar  avatar Carl Martin Rosenberg avatar Angus H. avatar Burl avatar Val Packett avatar 5hun Yanaura avatar Yuichi Murata avatar Daisuke Shimizu avatar Ciaran Downey avatar Ryo Shimizu avatar Hiroaki Nakamura avatar Dan Banta avatar Li-Wen Hsu avatar Peter Grehan avatar Denis Denisov avatar John Wachowski avatar Michael B. Sumulong avatar Claus Conrad avatar Mike avatar Matthew Closson avatar  avatar  avatar Vsevolod Stakhov avatar

Watchers

Pat Maddox avatar Richard Bowden avatar James Cloos avatar  avatar  avatar Rachelle Salvadora avatar Linz avatar Denis Dallaire avatar  avatar  avatar

uclcmd's Issues

uclcmd segfaults when including an empty file

The uclcmd program crashes with a segfault when including an empty file on FreeBSD 10.3. I suspect this a side effect of how FreeBSD handles mmap() calls with a length of zero (afaik it returns NULL which isn't the same as MAP_FAILED).

case sensitivity of keys

i tried uclcmd
thanks for it!
there's only one thing that confuses me:
uclcmd get -f /etc/pkg/FreeBSD.conf .FreeBSD.url
null
but .freebsd.url
works
is it on purpose that all keys are lower case?

Add a flag to enable case sensitivity of keys. When not enabled, lowercase all input

Allow `set` to write the result back to a file.

This can either be default behavior or an optional switch if it's deemed experimental.

Currently the process is:

uclcmd set -f /path/to/something foo bar > /path/to/something.tmp ; mv /path/to/something.tmp /path/to/something.

The process would be more robust in a script with error code checking and such, but that's the procedure currently. It does not work for non-existing keys.

So ideally the process would be:

uclcmd set [-w] -f /path/to/something foo bar

With bar replacing any previous value of foo, or if foo does not exist, adding that key value pair.

Data type handling could be improved.

Hi, firstly, thanks for uclmd. It has become a big part of a FreeBSD specific server management framework I'm developing. Working with configuration files for my shell based utility scripts is now really great, especially when it comes to using arrays.

I only just noticed a bug in my project, due to a set command not doing what I expected. When I try to set a key value pair with alphanumeric value starting with numbers it sets the value to a long number. I'm asuming uclcmd thinks that becuase it starts with a number, it must be a number, and something like atoa is returning a large integer.

Command used:

# uclcmd set -f test.conf name "100GB"

Expected result:

# cat test.conf 
name = "100GB";

Actual result:

# cat test.conf 
name = 107374182400;

I did notice that if I use the -t string argument to specify data type as string it works. I will now need to go and refactor all my code to specify the data type. Documentation seems a bit lacking for uclcmd, I had to guess the "string" and "number" data types, which seem to work. I couldn't find anywhere that the data-types are listed, yet I knew about the "array" and "object" data types from somewhere. Maybe I forgot where to look for help using uclcmd.

I can work on the data type detection logic when I get a bit more time. Would you be OK with my submitting a pull request for this if I find time to spend on it?

--noquotes does not work.

Here is my command:

uclcmd get -f /etc/pkg/FreeBSD.conf --noquotes freebsd.url

and the output:

uclcmd: unrecognized option `--noquotes'
Error: Unexpected option: 63

uclcmd segfaults

I just ran into this while using uclcmd to generate pkg-create(8) manifests from ucl fragments.. Various case sensitivity tests cause SIGSEGV:

I'd expect the following snippet to be parsed as key: [value, Value] if we are case insensitive, and separately if we are case aware.

Built off FreeBSD 12.0-CURRENT FreeBSD akai.skunkwerks.at 12.0-CURRENT FreeBSD 12.0-CURRENT #0 r311461: Thu Jan 5 22:46:38 UTC 2017 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64

# test.ucl 
key: value
Key: Value
KEYS: ValueS
 /t/ucl uclcmd get --yaml --keys --file test.ucl .keys
"ValueS"
 /t/ucl uclcmd get --yaml --keys --file test.ucl .KEYS
fish: “uclcmd get --yaml --keys --file…” terminated by signal SIGSEGV (Address boundary error)
 /t/ucl uclcmd get --yaml --keys --file test.ucl .KEY                                                                                                                                                (139) 
fish: “uclcmd get --yaml --keys --file…” terminated by signal SIGSEGV (Address boundary error)
 /t/ucl uclcmd get --yaml --keys --file test.ucl .key
[
    "value",
    "Value"
]
 /t/ucl uclcmd get --json --keys --file test.ucl .KEY
fish: “uclcmd get --json --keys --file…” terminated by signal SIGSEGV (Address boundary error)
 /t/ucl uclcmd get  --keys --file test.ucl .KEY                                                                                                                                                      (139) 
KEY=null
 /t/ucl uclcmd get  --keys --file test.ucl .key
key=[array]
 /t/ucl uclcmd get --json --keys --file test.ucl .key
[
    "value",
    "Value"
]
 /t/ucl uclcmd get --yaml --keys --file test.ucl .key
[
    "value",
    "Value"
]
 /t/ucl 

Bug 277666 - devel/uclcmd : uclcmd-0.2.20211204 get JSON and YAML output is broken.

The JSON and YAML output from uclcmd is invalid. Here is simple reproducer to show the result:

uclcmd get --json . <<EOF
foo [{bar: baz}]
EOF

The incorrect output is:

,
{
    ,
"foo": [
        ,
{
            "bar": "baz"
        }
    ]
}

The correct output would be:

{
    "foo": [
        {
            "bar": "baz"
        }
    ]
}

The YAML output is similarly broken, but it's partially hidden the more flexible syntax where the fields of an object are separated only by whitespaces instead of comma, newline and indentation.

The wrong YAML output (notice the extra newlines):

# Comment added to preserve both leading newlines in GitHub Markdown code block rendering.


foo: [
    ,
{
        bar: "baz"
    }
]

The correct YAML output would be:

foo: [
    {
        bar: "baz"
    }
]

It's possible the bug isn't directly in uclcmd-0.2.20211204 and that uclcmd only exposes a bug in libucl-0.9.0. As it is right now uclcmd can't be used to extract any values containing arrays or objects in JSON or YAML format. The UCL formatted output works is syntactically valid and correctly represents the emitted data. The tests were performed on FreeBSD 14.0p5/amd64 with the libucl and uclcmd installed from the latest branch of the official package repos.

This GitHub issue is a forwarded copy of the FreeBSD PR #277666. Sorry for reaching out via multiple channels at once.

Build fails with linking errors

Good day!

I have installed the latest version of libucl from ports, and cloned your master branch of uclcmd.

When running make, the build fails with various undefined reference to... errors.
Let me know what I can do to help! Thanks!

Here's the output:

$ make
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd.c -o uclcmd.o
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_common.c -o uclcmd_common.o
uclcmd_common.c:86:6: warning: implicit declaration of function 'ucl_lookup_path_char' is invalid in C99
      [-Wimplicit-function-declaration]
            ucl_lookup_path_char(root_obj, dst_prefix, input_sepchar));
            ^
/usr/include/sys/cdefs.h:650:65: note: expanded from macro '__DECONST'
#define __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
                                                                   ^
uclcmd_common.c:85:15: warning: cast to 'const void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast]
        parent_obj = __DECONST(ucl_object_t *,
                     ^
/usr/include/sys/cdefs.h:650:50: note: expanded from macro '__DECONST'
#define __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
                                                    ^
uclcmd_common.c:139:15: warning: cast to 'const void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast]
        parent_obj = __DECONST(ucl_object_t *,
                     ^
/usr/include/sys/cdefs.h:650:50: note: expanded from macro '__DECONST'
#define __DECONST(type, var)    ((type)(__uintptr_t)(const void *)(var))
                                                    ^
3 warnings generated.
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_get.c -o uclcmd_get.o
uclcmd_get.c:180:17: warning: implicit declaration of function 'ucl_lookup_path_char' is invalid in C99
      [-Wimplicit-function-declaration]
        found_object = ucl_lookup_path_char(found_object, node_name, input_sepchar);
uclcmd_get.c:180:15: warning: incompatible integer to pointer conversion assigning to 'const ucl_object_t *'
      (aka 'const struct ucl_object_s *') from 'int' [-Wint-conversion]
        found_object = ucl_lookup_path_char(found_object, node_name, input_sepchar);
                     ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
uclcmd_get.c:638:6: warning: incompatible integer to pointer conversion assigning to 'const ucl_object_t *'
      (aka 'const struct ucl_object_s *') from 'int' [-Wint-conversion]
        cur = ucl_lookup_path_char(obj, reqnode, input_sepchar);
            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_merge.c -o uclcmd_merge.o
uclcmd_merge.c:245:3: warning: implicit declaration of function 'ucl_array_index_of' is invalid in C99
      [-Wimplicit-function-declaration]
                ucl_array_index_of(dst_obj, sub_obj));
                ^
1 warning generated.
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_output.c -o uclcmd_output.o
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_parse.c -o uclcmd_parse.o
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_remove.c -o uclcmd_remove.o
uclcmd_remove.c:150:7: warning: implicit declaration of function 'ucl_array_index_of' is invalid in C99
      [-Wimplicit-function-declaration]
                    ucl_array_index_of(obj_parent, obj_child), ucl_object_key(obj_parent));
                    ^
1 warning generated.
cc -g -O0 -Wall -I/usr/include -I/usr/local/include -c uclcmd_set.c -o uclcmd_set.o
cc -L/usr/lib -L/usr/local/lib -lucl -o uclcmd uclcmd.o uclcmd_common.o uclcmd_get.o uclcmd_merge.o uclcmd_output.o uclcmd_
parse.o uclcmd_remove.o uclcmd_set.o
uclcmd_common.o: In function `get_object':
/usr/home/tparis/uclcmd/uclcmd_common.c:85: undefined reference to `ucl_lookup_path_char'
uclcmd_common.o: In function `get_parent':
/usr/home/tparis/uclcmd/uclcmd_common.c:139: undefined reference to `ucl_lookup_path_char'
uclcmd_get.o: In function `get_mode':
/usr/home/tparis/uclcmd/uclcmd_get.c:180: undefined reference to `ucl_lookup_path_char'
uclcmd_get.o: In function `get_cmd_none':
/usr/home/tparis/uclcmd/uclcmd_get.c:638: undefined reference to `ucl_lookup_path_char'
uclcmd_merge.o: In function `merge_mode':
/usr/home/tparis/uclcmd/uclcmd_merge.c:245: undefined reference to `ucl_array_index_of'
uclcmd_remove.o: In function `remove_main':
/usr/home/tparis/uclcmd/uclcmd_remove.c:150: undefined reference to `ucl_array_index_of'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
make: stopped in /usr/home/tparis/uclcmd

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.