@@ -4,6 +4,8 @@ using namespace winrt;
44using namespace winrt ::Windows::Foundation;
55using namespace winrt ::Windows::UI::UIAutomation;
66
7+ #define VERSION_STRING " 0.1.240505"
8+
79std::string get_current_time ()
810{
911 // [TIPS]c+20 runtime is too expensive, + 500k for following implement.
@@ -111,14 +113,14 @@ class Engine
111113
112114
113115
114- void usage ()
115- {
116- std::cerr << " Write all content of LiveCaptions Windows System Program into file, continually.Ctrl-C to exit." << std::endl;
117- std::cerr << " Usage: get-livecatpions file" << std::endl;
118- std::cerr << " Options:" << std::endl;
119- std::cerr << " file filename, to save content of live catpions running." << std::endl;
120- exit (1 );
121- }
116+ // void usage()
117+ // {
118+ // std::cerr << "Write all content of LiveCaptions Windows System Program into file, continually.Ctrl-C to exit." << std::endl;
119+ // std::cerr << "Usage: get-livecatpions file" << std::endl;
120+ // std::cerr << "Options:" << std::endl;
121+ // std::cerr << " file filename, to save content of live catpions running." << std::endl;
122+ // exit(1);
123+ // }
122124bool touch_file (const std::string &filename)
123125{
124126 std::ofstream file (filename,std::ios::app);
@@ -129,18 +131,39 @@ bool touch_file(const std::string &filename)
129131
130132int main (int argc, char *argv[])
131133{
132- if ((argc != 2 ) || (!touch_file (argv[1 ])))
133- usage ();
134- if (!Engine::is_livecaption_running ())
135- {
136- std::cerr << " [Error]Live Captions is not running." <<std::endl;
137- exit (1 );
134+
135+
136+ std::string strFileName;
137+ argparse::ArgumentParser program (" get-livecaptions" ,VERSION_STRING);
138+ program.add_argument (" -o" , " --output" )
139+ .metavar (" file" )
140+ .help (" filename, write content into file. use - for console." )
141+ .required ();
142+
143+ program.add_description (" Write the content of LiveCaptions Windows System Program into file, continually." );
144+ program.add_epilog (" use ctrl-c to exit program." );
145+
146+ try {
147+ if (argc==1 ) {program.print_help ();exit (1 );}
148+ program.parse_args (argc, argv);
149+ strFileName = program.get <std::string>(" --output" );
150+
151+ if (!Engine::is_livecaption_running ())
152+ {
153+ std::cerr << " [Error]Live Captions is not running." <<std::endl;
154+ exit (1 );
155+ }
156+ }
157+ catch (const std::exception& err) {
158+ std::cerr << err.what () << std::endl;
159+ std::cerr << program;
160+ return 1 ;
138161 }
139162
140163 try
141164 {
142165 asio::io_context io_context (1 );
143- Engine eng (argv[ 1 ] );
166+ Engine eng (strFileName );
144167
145168 asio::signal_set signals (io_context, SIGINT, SIGTERM);
146169 signals.async_wait ([&](auto , auto ){
0 commit comments