diff options
author | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-15 12:34:09 +0100 |
---|---|---|
committer | Andreas Baumann <mail@andreasbaumann.cc> | 2014-11-15 12:34:09 +0100 |
commit | 160aa748295f1846d6d599d7145cd5d7bdd82f5f (patch) | |
tree | 694c4fbfd56ef6852370eec42280b3052a46dd0b /src/biruda.c | |
parent | 75df5abae42888bd5bf01fc4a8bd1215413cab67 (diff) | |
download | biruda-160aa748295f1846d6d599d7145cd5d7bdd82f5f.tar.gz biruda-160aa748295f1846d6d599d7145cd5d7bdd82f5f.tar.bz2 |
added status to cli mode
Diffstat (limited to 'src/biruda.c')
-rw-r--r-- | src/biruda.c | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/src/biruda.c b/src/biruda.c index 3543d86..eeee719 100644 --- a/src/biruda.c +++ b/src/biruda.c @@ -35,7 +35,9 @@ #ifndef _WIN32 #include <strings.h> #include <ctype.h> +#include <stdarg.h> #include "linenoise.h" +#include "http_lib.h" #endif #include "port.h" @@ -221,6 +223,8 @@ static char *commands[] = { "help", "quit", "status", NULL }; +static bool print_colors = false; + static void completion_func( const char *buf, linenoiseCompletions *lc ) { unsigned int i; @@ -244,23 +248,43 @@ static void print_help( ) ); } -static void print_status( ) +static void print_error( const char *fmt, ... ) { - puts( "\nStatus\n" ); + va_list ap; + char buf[1024]; + + va_start( ap, fmt ); + (void)vsnprintf( buf, sizeof( buf ), fmt, ap ); + va_end( ap ); + + if( print_colors ) { + printf( "%c[9%dmERROR: %s%c[0m\n", 27, 1, buf, 27 ); + } else { + puts( buf ); + } } -static void print_error( const char *error, bool colors ) +static void print_status( ) { - if( colors ) { - printf( "%c[9%dmERROR: %s%c[0m\n", 27, 1, error, 27 ); + http_server = "localhost"; + http_port = 8080; + char *url = "status"; + char *data = NULL; + int len; + http_retcode ret = http_get( url, &data, &len, NULL ); + if( ret == 200 ) { + fwrite( data, len,1, stdout ); } else { - puts( error ); + print_error( "HTTP error %d", ret ); } + free( data ); } static int start_interactive( bool colors ) { char history_filename[1024]; + + print_colors = colors; char *home = getenv( "HOME" ); if( home != NULL ) { @@ -295,7 +319,7 @@ static int start_interactive( bool colors ) } else if( strncasecmp( line, "status", 6 ) == 0 ) { print_status( ); } else { - print_error( "Bad command.", colors ); + print_error( "Bad command." ); } } @@ -333,7 +357,10 @@ int main( int argc, char *argv[] ) } if( args_info.cli_given ) { - return start_interactive( !args_info.no_colors_given ); + int ret = start_interactive( !args_info.no_colors_given ); + cfg_free( cfg ); + cmdline_parser_free( &args_info ); + return( ( ret == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE ); } unsigned int has_master = cfg_size( cfg, "master" ); |