Skip to content

Conversation

@jupe
Copy link
Contributor

@jupe jupe commented Jul 17, 2018

Status

READY

Migrations

NO

Description

Several improvements:

  • optional disable man pages - to save memory
  • variable can be also integer
  • store previous retcode to ? -variable
  • store prompt as PS1 -variable (possible to change using `set´ -cmd)
  • api to request screen size: cmd_request_screen_size(void) -> generates variables: COLUMNS, LINES
  • true and false -commands
  • ctrl+w support (remove previous word)
  • escape character parsing (IOTSYSTOOL-131)
  • Improve test coverage and added valgrind mem leak test

NOTE: known issues

  • args like "ab""cd" cause two arguments: ["ab", "cd"]
  • "~weird" escaped arg inputs like "\\\\"\" causes weird results: "\\\\"\"

Todos

  • Tests
  • Documentation

jupe and others added 19 commits July 14, 2018 16:33
* add option to ignore man pages by flag CMDLINE_INCLUDE_MAN=<bool>
* add true and false commands and tests for available operators and, or, semicolon
* add retcode tests
* cleaning comments
* rename define CMDLINE_INCLUDE_MAN to MBED_CMDLINE_INCLUDE_MAN
* remove underscore macro - use it always
* add warning trace if max arguments reached
* clean up some compiler warnings
* allow to store also int values for variables
* fixes alt+left behaviour
* add "?" variable for last retcode
* add function for request screen size
WIP
* add escaping support
* prompt and retcode format is now as variable
@jupe
Copy link
Contributor Author

jupe commented Jul 20, 2018

#77 need to to be fixed first to get this PR green

@jupe jupe requested review from YifeiZuo01 and kuggenhoffen July 20, 2018 08:08
}
// // alias test
// extern void replace_alias(const char *str, const char *old_str, const char *new_str);
// TEST(cli, cmd_alias_1)

This comment was marked as resolved.

test/Test.cpp Outdated
ARRAY_CMP("\r\nvariables:\r\n"
"PS1='/>'\r\n"
"?=-1\r\n"
"\r\x1b[2K/> \x1b[1D", buf);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with macros

test/Test.cpp Outdated
ARRAY_CMP("\r\nvariables:\r\n"
"PS1='/>'\r\n"
"?=0\r\n"
"\r\x1b[2K/> \x1b[1D", buf);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with macros

#define TRACE_GROUP "cmdL"

#ifndef MBED_CMDLINE_BOOT_MESSAGE
#define MBED_CMDLINE_BOOT_MESSAGE "ARM Ltd\r\n"

This comment was marked as resolved.

#endif
//include manuals or not (save memory a little when not include)
#define INCLUDE_MAN
#ifndef MBED_CMDLINE_INCLUDE_MAN

This comment was marked as resolved.

Copy link

@YifeiZuo01 YifeiZuo01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test/Test.cpp Outdated
ARRAY_CMP("\r\nalias:\r\n"
"_ 'alias'\r\n"
"_ 'alias foo'\r\n"
"\r\x1b[2K/> \x1b[1D", buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with macros

test/Test.cpp Outdated
"foo 'bar'\r\n"
"_ 'alias'\r\n"
"_ 'alias foo bar'\r\n"
"\r\x1b[2K/> \x1b[1D", buf);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace with macros

YifeiZuo01
YifeiZuo01 previously approved these changes Aug 7, 2018
Copy link

@YifeiZuo01 YifeiZuo01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@jupe jupe requested a review from tommikas August 7, 2018 10:40
@jupe jupe added this to the v0.4.0 milestone Aug 7, 2018
@jupe jupe requested review from SeppoTakalo and removed request for SeppoTakalo, kuggenhoffen and tommikas August 7, 2018 11:02
@jupe jupe requested a review from mikter August 22, 2018 18:56
@mikter
Copy link

mikter commented Aug 23, 2018

ok for me.
when using command line and pasting long command strings that goes past the screen used to cause wrong behaviour. is that handled in here or is it a known issue after this?

@tommikas
Copy link

If the limit is the line going past the screen it sounds more like an issue of the terminal application than the cli library. The only limitations it has are the serial input buffer size (was for example 768 bytes in mbed-os-cliapp at some point), mbed-client-cli input buffer size (2000 bytes by default), and how fast the mcu can move the bytes out of one to the other. For example on a K64F with those buffer sizes pasting in a string of up to around 1500 characters at once worked fine. (Though admittedly that may have been with echo off.. It's been a while.)

}
return NULL;
}
static const char* strrevchr(const char* from, const char* to, const char c)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is this function meant to do? Find the last occurrence of a character in a string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly - between two pointers

}
while((from > to) && (*from == c)) {
from--;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't the above loop skip past the first block of the searched for characters if it's the last character before NUL in the range?

For example if the string between the pointers is "aaaabaabbb\0\0" and you search for 'b'.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah that's true - logic is really that it tries (fixing one bug soon) to find last character X but skip last ones if there is multiple--> is used to find "last" space....

strrevchr("aaaabaabbb\0\0" - 'b') --> bbb\0\0

add more documentation for function
}
while (from > to) {
if (*from == ' ') {
return from+1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So actually this returns a pointer to the character following the last space (ignoring trailing spaces).

Alright, makes sense now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

@jupe jupe merged commit 1554081 into master Aug 23, 2018
@jupe jupe deleted the refactoring branch August 23, 2018 14:38
@jupe
Copy link
Contributor Author

jupe commented Aug 23, 2018

merged - please open ticket if you find any issues - as usual :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants