Skip to content

Commit f901dc1

Browse files
src/preseq.cpp: changing to use CLI11 for the subcommands. Nice!
1 parent 074facd commit f901dc1

1 file changed

Lines changed: 56 additions & 50 deletions

File tree

src/preseq.cpp

Lines changed: 56 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,89 @@
1-
/* preseq: to predict properties of genomic sequencing libraries
1+
/* preseq: a tool for analyzing sequencing library complexity
22
*
3-
* Copyright (C) 2013-2024 University of Southern California and
3+
* Copyright (C) 2013-2025 University of Southern California and
44
* Andrew D. Smith and Timothy Daley
55
*
6-
* Authors: Timothy Daley, Chao Deng, Victoria Helus, and Andrew Smith
6+
* Author: Andrew D Smith
77
*
8-
* This program is free software: you can redistribute it and/or
9-
* modify it under the terms of the GNU General Public License as
10-
* published by the Free Software Foundation, either version 3 of the
11-
* License, or (at your option) any later version.
8+
* This program is free software: you can redistribute it and/or modify it
9+
* under the terms of the GNU General Public License as published by the Free
10+
* Software Foundation, either version 3 of the License, or (at your option)
11+
* any later version.
1212
*
13-
* This program is distributed in the hope that it will be useful, but
14-
* WITHOUT ANY WARRANTY; without even the implied warranty of
15-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16-
* General Public License for more details.
13+
* This program is distributed in the hope that it will be useful, but WITHOUT
14+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16+
* more details.
1717
*
18-
* You should have received a copy of the GNU General Public License
19-
* along with this program. If not, see
20-
* <http://www.gnu.org/licenses/>.
18+
* You should have received a copy of the GNU General Public License along
19+
* with this program. If not, see <http://www.gnu.org/licenses/>.
2120
*/
2221

2322
#include "bound_pop.hpp"
2423
#include "c_curve.hpp"
24+
#include "common.hpp"
2525
#include "gc_extrap.hpp"
2626
#include "lc_extrap.hpp"
2727
#include "pop_size.hpp"
2828

29+
#include "CLI11/CLI11.hpp"
30+
2931
#include <config.h>
3032

3133
#include <cstdlib>
3234
#include <iostream>
33-
#include <sstream>
35+
#include <memory>
3436
#include <string>
3537

36-
static std::string
37-
usage_message() {
38-
std::ostringstream oss;
39-
oss << "preseq: a program for analyzing library complexity\n"
40-
"Version: ";
41-
oss << VERSION;
42-
oss << "\n\n"
43-
"Usage: preseq <command> [OPTIONS]\n\n"
44-
"<command>: c_curve generate complexity curve for a library\n"
45-
" lc_extrap predict the yield for future experiments\n"
46-
" gc_extrap predict genome coverage low input\n"
47-
" sequencing experiments\n"
48-
" bound_pop lower bound on population size\n"
49-
" pop_size estimate number of unique species\n";
50-
return oss.str();
51-
}
52-
5338
int
54-
main(int argc, char *argv[]) {
39+
main(int argc, char *argv[]) { // NOLINT(*-c-arrays)
40+
CLI::App app{"preseq: a tool for analyzing sequencing library complexity"};
41+
argv = app.ensure_utf8(argv);
42+
app.formatter(std::make_shared<preseq_formatter>());
43+
app.usage("\nUsage: preseq command [OPTIONS]");
44+
// if (argc >= 3)
45+
// app.footer(rlstrip(footer_msg));
46+
47+
app.require_subcommand(0, 1);
48+
app.allow_extras();
49+
50+
bool print_version{};
51+
52+
// clang-format off
53+
app.add_flag("--version", print_version, "output version information and exit");
54+
const auto lc_extrap = app.add_subcommand("lc_extrap", rlstrip(lc_extrap::about_msg));
55+
const auto gc_extrap = app.add_subcommand("gc_extrap", rlstrip(gc_extrap::about_msg));
56+
const auto pop_size = app.add_subcommand("pop_size", rlstrip(pop_size::about_msg));
57+
const auto bound_pop = app.add_subcommand("bound_pop", rlstrip(bound_pop::about_msg));
58+
const auto c_curve = app.add_subcommand("c_curve", rlstrip(c_curve::about_msg));
59+
// clang-format on
60+
5561
if (argc < 2) {
56-
std::cerr << usage_message() << '\n';
62+
// std::println("{}", app.help());
63+
std::cout << app.help() << '\n';
5764
return EXIT_SUCCESS;
5865
}
66+
CLI11_PARSE(app, argc, argv);
5967

60-
static const std::string cmd = argv[1]; // NOLINT(*-pointer-arithmetic)
61-
62-
if (cmd == "lc_extrap")
63-
return lc_extrap_main(argc - 1, argv + 1);
68+
if (print_version) {
69+
std::cout << VERSION << '\n';
70+
return EXIT_SUCCESS;
71+
}
6472

65-
if (cmd == "c_curve")
66-
return c_curve_main(argc - 1, argv + 1);
73+
if (app.got_subcommand(lc_extrap))
74+
return lc_extrap::main(argc - 1, argv + 1);
6775

68-
if (cmd == "gc_extrap")
69-
return gc_extrap_main(argc - 1, argv + 1);
76+
if (app.got_subcommand(gc_extrap))
77+
return gc_extrap::main(argc - 1, argv + 1);
7078

71-
if (cmd == "bound_pop")
72-
return bound_pop_main(argc - 1, argv + 1);
79+
if (app.got_subcommand(c_curve))
80+
return c_curve::main(argc - 1, argv + 1);
7381

74-
if (cmd == "pop_size")
75-
return pop_size_main(argc - 1, argv + 1);
82+
if (app.got_subcommand(pop_size))
83+
return pop_size::main(argc - 1, argv + 1);
7684

77-
std::cerr << "Error: unrecognized command: "
78-
<< argv[1] // NOLINT(*-pointer-arithmetic)
79-
<< '\n'
80-
<< usage_message() << '\n';
85+
if (app.got_subcommand(bound_pop))
86+
return bound_pop::main(argc - 1, argv + 1);
8187

8288
return EXIT_FAILURE;
8389
}

0 commit comments

Comments
 (0)