Mercurial > hg > orthanc
diff OrthancServer/Sources/main.cpp @ 4412:68b96234fbd6
automated generation of the cheat sheet of the REST API, to be included in the Orthanc Book
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 28 Dec 2020 11:57:48 +0100 |
parents | ad646ff506d0 |
children | 22a1352a0823 |
line wrap: on
line diff
--- a/OrthancServer/Sources/main.cpp Sun Dec 27 11:31:50 2020 +0100 +++ b/OrthancServer/Sources/main.cpp Mon Dec 28 11:57:48 2020 +0100 @@ -661,6 +661,8 @@ << "\t\t\tthe last execution of Orthanc" << std::endl << " --openapi=[file]\twrite the OpenAPI documentation and exit" << std::endl << "\t\t\t(if \"file\" is \"-\", dumps to stdout)" << std::endl + << " --cheatsheet=[file]\twrite the cheat sheet of REST API as CSV" << std::endl + << "\t\t\tand exit (if \"file\" is \"-\", dumps to stdout)" << std::endl << " --version\t\toutput version information and exit" << std::endl << std::endl << "Fine-tuning of log categories:" << std::endl; @@ -1793,6 +1795,41 @@ return -1; } } + else if (boost::starts_with(argument, "--cheatsheet=")) + { + std::string target = argument.substr(13); + + try + { + std::string cheatsheet; + + { + SQLiteDatabaseWrapper inMemoryDatabase; + inMemoryDatabase.Open(); + MemoryStorageArea inMemoryStorage; + ServerContext context(inMemoryDatabase, inMemoryStorage, true /* unit testing */, 0 /* max completed jobs */); + OrthancRestApi restApi(context, false /* no Orthanc Explorer */); + //restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "https://api.orthanc-server.com/index.html"); + restApi.GenerateReStructuredTextCheatSheet(cheatsheet, "http://localhost:8000/a.html"); + context.Stop(); + } + + if (target == "-") + { + std::cout << cheatsheet; // Print to stdout + } + else + { + SystemToolbox::WriteFile(cheatsheet, target); + } + return 0; + } + catch (OrthancException&) + { + LOG(ERROR) << "Cannot export REST cheat sheet as file \"" << target << "\""; + return -1; + } + } else { LOG(WARNING) << "Option unsupported by the core of Orthanc: " << argument;