Git Product home page Git Product logo

tcli's People

Contributors

dpse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

starrysec

tcli's Issues

Release tag?

Could you tag a commit you are particularly happy with to make a release?

tclie_init(): Output function gets &tclie_t, not arg as expected.

When using tclie_init(&tclie, output_fn, output_fn_arg), the output function is being called with &tclie instead of arg.

Is this expected?

When using tcli_init(&tcli, output_fn, output_fn_arg), the output function is called with output_fn_arg, as I would expect.

feature request: pattern matched commands

A feature I've used in past embedded CLI systems was a regularly formed syntax for the command usage description, which the command parser used to determine the validity of arguments.

Here's some examples of the 'usage descriptions':

Description Comment
reset Single word command, must match exactly.
config save Two word command, spaces around the words are ignored.
can speed <rate> Two word command, with mandatory argument.
set <attr> [value] One word command, with mandatory and optional argument.
echo ... One word command, with arbitrary number of arguments.
<reg> = <value> One word command ('=') embedded between mandatory arguments.
when <reg> is <value> echo ... Three word command, with two mandatory arguments and arbitrary optional.

The command handler worked just as yours does now, passing in all words in the argument as argc, argv.

The improvements over what you have now is:

  • Encourgaing usage document strings along with description
  • min_args/max_args can go away (determined when matching the input against the usage string)
  • Supports commands embedded between arguments (ie the <reg> = <value> case)

tclie_pattern_match: Add missing #if TCLI_COMPLETE

Add missing TCLI_COMPLETE preprocessor barrier:

diff -u a/source/tclie.c b/source/tclie.c
--- a/source/tclie.c    2022-09-20 15:36:47.499476363 -0400
+++ b/source/tclie.c    2022-09-20 15:37:59.739855525 -0400
@@ -645,8 +645,10 @@ static bool tclie_pattern_match(tclie_t
    };
 
    const bool matches = tclie_pattern_match_token(&token, &p);
+#if TCLI_COMPLETE
    if (arg_index != 0)
        tclie_pattern_match_complete_options(&p);
+#endif
    return matches && arg_index == argc;
 }
 #endif

tclie_pattern_compare: Do not assume all strings have unique storage.

The assert(target != subject) in tclie_pattern_compare() fails on systems when the compiler optimizes const char * strings that have the same content to the same memory location (ie GCC optimization level -Os or -fmerge-constants).

If two pointers are equal, then by definition the strings are the same. Return true instead of assert.

Suggested patch:

diff -u a/source/tclie.c b/source/tclie.c
--- a/source/tclie.c    2022-09-20 15:36:47.499476363 -0400
+++ b/source/tclie.c    2022-09-20 15:37:59.739855525 -0400
@@ -112,7 +112,10 @@ static bool tclie_pattern_compare(const
 {
    assert(target);
    assert(subject);
-   assert(target != subject);
+
+   if (target == subject) {
+       return true;
+    }
 
    while (target_len != 0 && *target != '\0' && *subject != '\0') {
        if (*target++ != *subject++)

config structs: struct typedef should not itself be 'const'

The typedef for a struct should not itself be 'const', ie:

This is bad:

typedef const struct foo_s {
} foo_t;

This is preferred:

typedef struct foo_s {
} foo_t;

Rationale is that with the former, it is not possible to dynamically construct command definitions at runtime.

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.