Skip to content

Commit

Permalink
Fixed: [Get the expanded string of entire command executed even if en…
Browse files Browse the repository at this point in the history
…tered string is partial #65 ](#65)
  • Loading branch information
olofhagsand committed Oct 21, 2021
1 parent 4564124 commit 23b4db5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Expected: November 2021

### Corrected Bugs

* Fixed: [Get the expanded string of entire command executed even if entered string is partial #65 ](https://github.com/clicon/cligen/issues/65)
* Fixed: [Performance issue when parsed string size is damn large #66](https://github.com/clicon/cligen/issues/66)

## 5.3.0
Expand Down
29 changes: 28 additions & 1 deletion cligen_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,8 @@ cliread_parse(cligen_handle h,
cvec *cvr = NULL; /* Rest variant, eg remaining string in each step */
cg_var *cv;
cvec *cvv = NULL; /* Top-level vars/val vector with just command as 0th element */
cbuf *cb = NULL;
int i;

if (cvvall == NULL || cvec_len(cvvall) != 0){
errno = EINVAL;
Expand All @@ -683,7 +685,15 @@ cliread_parse(cligen_handle h,
if ((cv = cvec_add(cvvall, CGV_REST)) == NULL)
goto done;
cv_name_set(cv, "cmd"); /* the whole command string */
cv_string_set(cv, string); /* the whole command string */
/* The whole command string as user entered.
* Note as discussed in https://github.com/clicon/cligen/issues/65
* one may want the fully expanded string instead, which now
* REPLACES this original string, after cvvall is populated in match_pattern_exact.
* It is still kept in case you want to keep the original, then comment the
* replacement further down.
*/
cv_string_set(cv, string);

/* Why is this created separately from cvvall? */
if ((cvv = cvec_start(string)) == NULL)
goto done;
Expand All @@ -697,13 +707,30 @@ cliread_parse(cligen_handle h,
&match_obj, &ptmatch,
result, reason) < 0)
goto done;
/* REPLACE the original string in first position with expanded string
* If you want the original string comment this section.
*/
if ((cb = cbuf_new()) == NULL)
goto done;
for (i=1; i<cvec_len(cvvall); i++){
if (i>1)
cprintf(cb, " ");
if ((cv = cvec_i(cvvall,i)) == NULL)
goto done;
cv2cbuf(cv, cb);
}
cv = cvec_i(cvvall,0);
cv_string_set(cv, cbuf_get(cb));

/* Map from ghost object match_obj to real object */
if (match_obj && match_obj->co_ref)
*co_orig = match_obj->co_ref;
else
*co_orig = match_obj;
retval = 0;
done:
if (cb)
cbuf_free(cb);
if (cvv)
cvec_free(cvv);
if (cvt)
Expand Down

0 comments on commit 23b4db5

Please sign in to comment.