Haio 0.2.X
Homebrew Asset IO/CDN
Loading...
Searching...
No Matches
haio_cli.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "haio.hpp"
4
5#include <optional>
6#include <span>
7#include <string>
8#include <string_view>
9#include <vector>
10
11/**
12 * the convert command line.
13 *
14 * it used to be namespace Haio::Convert, which now belongs to the colour conversion
15 * family -- a name cannot be a namespace and a function template at once.
16 */
17namespace Haio::Cli {
18
32
33struct ParseError {
34 std::string message;
35 std::string token;
36
37 explicit operator bool() const noexcept;
38};
39
40struct Token {
42 std::string value;
43 std::string arg;
46 std::optional<Rect> rect;
47 std::optional<Size> size;
48 int radius = 0;
49 int percent = 0;
51 size_t limit = 0; /**< zero means the palette is used whole */
53};
54
55struct Command {
57
58 /**
59 * an option that has been read and not yet used by anything.
60 *
61 * settings stack and operations take them, so "-filter bayer -palete cga" works
62 * and "-palete cga -filter bayer" does not: by the time the filter is written
63 * down the palette has already gone by, and nothing after it wants one. a setting
64 * still waiting when the line ends is a mistake worth stopping for, because it
65 * was written in the belief that it would do something.
66 */
67 struct Pending {
68 std::string option;
69 std::string value;
70 };
71 std::optional<Pending> pendingFilter;
72 std::optional<Pending> pendingLimit;
73 Limit pendingLimitHow = Limit::Spread; /**< only meaningful when pendingLimit is set */
74
75 bool hasInput = false;
76 bool hasGenerator = false;
77 bool outputIsStdout = false;
78 std::string inputPath;
79 std::string outputPath;
80 std::string inputFormatName;
81 std::string outputFormatName;
84
85 /** which colour to store inside the output, when -pix_fmt named one */
86 std::optional<Color> outputColor;
87 std::string outputColorName;
88
89 std::vector<Token> tokens;
90};
91
92Command parseArgs(int argc, char* argv[]);
93Command parseCommandLine(std::string_view text);
94std::vector<std::string> lexCommandLine(std::string_view text);
95Pipeline buildPipeline(const Command& command);
96int runCli(int argc, char* argv[]);
97
98bool parseSizeToken(std::string_view text, Size& out);
99bool parseCropGeometryToken(std::string_view text, Rect& out);
100bool parseRectToken(std::string_view text, Rect& out);
101
102}
bool parseSizeToken(std::string_view text, Size &out)
Definition parser.cpp:516
std::string arg
Definition haio_cli.hpp:43
ParseError error
Definition haio_cli.hpp:56
std::string inputPath
Definition haio_cli.hpp:78
bool parseCropGeometryToken(std::string_view text, Rect &out)
Definition parser.cpp:520
Command parseCommandLine(std::string_view text)
Definition parser.cpp:540
std::optional< Rect > rect
Definition haio_cli.hpp:46
std::optional< Size > size
Definition haio_cli.hpp:47
std::string inputFormatName
Definition haio_cli.hpp:80
std::optional< Pending > pendingFilter
Definition haio_cli.hpp:71
std::optional< Pending > pendingLimit
Definition haio_cli.hpp:72
std::vector< std::string > lexCommandLine(std::string_view text)
Definition parser.cpp:528
std::vector< Token > tokens
Definition haio_cli.hpp:89
Pipeline buildPipeline(const Command &command)
std::string outputFormatName
Definition haio_cli.hpp:81
Command parseArgs(int argc, char *argv[])
Definition parser.cpp:544
TokenType type
Definition haio_cli.hpp:41
std::string outputColorName
Definition haio_cli.hpp:87
std::string value
Definition haio_cli.hpp:42
std::string outputPath
Definition haio_cli.hpp:79
int runCli(int argc, char *argv[])
Definition cli.cpp:109
std::optional< Color > outputColor
Definition haio_cli.hpp:86
bool parseRectToken(std::string_view text, Rect &out)
Definition parser.cpp:524
std::string message
Definition haio_cli.hpp:34