@@ -21,14 +21,15 @@ class rehead_prog_args
2121 std::string input_path_;
2222 std::string output_path_;
2323 std::string sample_ids_path_;
24- int expected_arg_sz_ = 3 ;
24+ int expected_arg_sz_ = 2 ;
2525 bool help_ = false ;
2626public:
2727 rehead_prog_args () :
2828 long_options_ (
2929 {
3030 {" help" , no_argument, 0 , ' h' },
3131 {" sample-ids" , required_argument, 0 , ' i' },
32+ {" output" , required_argument, 0 , ' o' },
3233 {0 , 0 , 0 , 0 }
3334 })
3435 {
@@ -43,10 +44,11 @@ class rehead_prog_args
4344
4445 void print_usage (std::ostream& os)
4546 {
46- os << " Usage: sav rehead [opts ...] <headers_file> <in.sav> <out.sav> \n " ;
47- os << " Or: sav rehead [opts ...] -i <sample_ids_file> <in.sav> <out.sav> \n " ;
47+ os << " Usage: sav rehead [opts ...] <headers_file> <in.sav> -o <out.sav> \n " ;
48+ os << " Or: sav rehead [opts ...] -i <sample_ids_file> <in.sav> -o <out.sav> \n " ;
4849 os << " \n " ;
4950 os << " -h, --help Print usage\n " ;
51+ os << " -o, --output Path to output file\n " ;
5052 os << " -I, --sample-ids Path to file containing list of sample IDs that will replace existing IDs.\n " ;
5153 os << std::flush;
5254 }
@@ -55,14 +57,17 @@ class rehead_prog_args
5557 {
5658 int long_index = 0 ;
5759 int opt = 0 ;
58- while ((opt = getopt_long (argc, argv, " hI:" , long_options_.data (), &long_index )) != -1 )
60+ while ((opt = getopt_long (argc, argv, " hI:o: " , long_options_.data (), &long_index )) != -1 )
5961 {
6062 char copt = char (opt & 0xFF );
6163 switch (copt)
6264 {
6365 case ' I' :
6466 sample_ids_path_ = std::string (optarg ? optarg : " " );
65- expected_arg_sz_ = 2 ;
67+ expected_arg_sz_ = 1 ;
68+ break ;
69+ case ' o' :
70+ output_path_ = std::string (optarg ? optarg : " " );
6671 break ;
6772 case ' h' :
6873 help_ = true ;
@@ -76,12 +81,17 @@ class rehead_prog_args
7681
7782 if (remaining_arg_count < expected_arg_sz_)
7883 {
79- std::cerr << " Too few arguments\n " ;
84+ std::cerr << " Error: too few arguments\n " ;
8085 return false ;
8186 }
8287 else if (remaining_arg_count > expected_arg_sz_)
8388 {
84- std::cerr << " Too many arguments\n " ;
89+ std::cerr << " Error: too many arguments\n " ;
90+ return false ;
91+ }
92+ else if (output_path_.empty ())
93+ {
94+ std::cerr << " Error: --output is a required argument\n " ;
8595 return false ;
8696 }
8797 else
@@ -314,4 +324,4 @@ int rehead_main(int argc, char **argv)
314324 }
315325
316326 return EXIT_SUCCESS;
317- }
327+ }
0 commit comments