summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 09:47:09 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-04 09:47:09 +0100
commitd5d78969be2903d30b948ba14353e6d476eb32a8 (patch)
treeea076c969484635f3a4d53fc7b700decdbadef9e
parentf30a66ffe8752d370ad211f9e331ed25538a263e (diff)
downloadbiruda-d5d78969be2903d30b948ba14353e6d476eb32a8.tar.gz
biruda-d5d78969be2903d30b948ba14353e6d476eb32a8.tar.bz2
added a -F <commandfile> option for easier batch execution
-rw-r--r--src/biruda.c27
-rw-r--r--src/biruda.ggo26
-rw-r--r--src/cli.c6
-rw-r--r--src/cli.h4
4 files changed, 44 insertions, 19 deletions
diff --git a/src/biruda.c b/src/biruda.c
index b900fcc..8e2d9ce 100644
--- a/src/biruda.c
+++ b/src/biruda.c
@@ -300,18 +300,33 @@ int main( int argc, char *argv[] )
return( ( test_config( &args_info ) == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE );
}
- if( args_info.cli_given ) {
+ if( args_info.cli_given || args_info.filename_given ) {
+ FILE *in = stdin;
+ if( args_info.filename_given ) {
+ in = fopen( args_info.filename_arg, "r" );
+ if( in == NULL ) {
+ fprintf( stderr, "ERROR: Unable to open command file '%s'\n", args_info.filename_arg );
+ cfg_free( cfg );
+ cmdline_parser_free( &args_info );
+ exit( EXIT_FAILURE );
+ }
+ }
+ int ret;
#ifndef _WIN32
- int ret = start_interactive( !args_info.no_colors_given );
+ ret = start_interactive( ( in == stdin ) ? !args_info.no_colors_given : false, in );
#else
- fprintf( stderr, "FATAL: No CLI mode implemented for Windows currently!\n" );
- int ret = -1;
+ if( args_info.filename_given ) {
+ ret = start_interactive( false, in );
+ } else {
+ fprintf( stderr, "FATAL: No CLI mode implemented for Windows currently!\n" );
+ ret = -1;
+ }
#endif
cfg_free( cfg );
cmdline_parser_free( &args_info );
- return( ( ret == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE );
+ exit( ( ret == 0 ) ? EXIT_SUCCESS : EXIT_FAILURE );
}
-
+
unsigned int has_master = cfg_size( cfg, "master" );
if( has_master ) {
if( create_master( cfg ) != 0 ) {
diff --git a/src/biruda.ggo b/src/biruda.ggo
index c204713..9b2fdc6 100644
--- a/src/biruda.ggo
+++ b/src/biruda.ggo
@@ -1,7 +1,7 @@
package "Biruda build service"
version "0.0.1"
usage "biruda [options]"
-description "Biruda node"
+description "Biruda Service"
section "Main Options"
option "config-file" c
@@ -21,14 +21,6 @@ section "Main Options"
"increase verbosity (can be given multiple times)"
optional multiple
- option "cli" i
- "start in command line interface (CLI), interactive mode"
- optional
-
- option "no-colors" -
- "disable colors in CLI mode"
- optional
-
section "Unix Daemon"
option "foreground" f
@@ -49,3 +41,19 @@ section "Unix Daemon"
"the unpriviledged user the daemon should run as"
string typestr="user"
optional
+
+section "Command Line Interface"
+
+ option "cli" i
+ "start in command line interface (CLI), interactive mode"
+ optional
+
+ option "no-colors" -
+ "disable colors in CLI mode"
+ optional
+
+ option "filename" F
+ "filename to read commands from and execute them"
+ string typestr="filename"
+ optional
+
diff --git a/src/cli.c b/src/cli.c
index 3f2e7fd..253f104 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -200,7 +200,7 @@ static void stop_worker( const char *worker_name )
}
}
-int start_interactive( bool colors )
+int start_interactive( bool colors, FILE *in )
{
char history_filename[1024];
@@ -208,7 +208,7 @@ int start_interactive( bool colors )
http_server = "localhost";
http_port = 8080;
- is_interactive = isatty( fileno( stdin ) );
+ is_interactive = isatty( fileno( in ) );
print_colors = is_interactive ? colors : false;
if( is_interactive ) {
@@ -257,7 +257,7 @@ int start_interactive( bool colors )
free( line );
line = buf;
} else {
- if( fgets( buf, sizeof( buf ), stdin ) == NULL ) {
+ if( fgets( buf, sizeof( buf ), in ) == NULL ) {
cleanup_worker_names( );
return EXIT_SUCCESS;
}
diff --git a/src/cli.h b/src/cli.h
index f362088..c80fab6 100644
--- a/src/cli.h
+++ b/src/cli.h
@@ -3,6 +3,8 @@
#include "port.h"
-int start_interactive( bool colors );
+#include <stdio.h>
+
+int start_interactive( bool colors, FILE *in );
#endif