1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#pragma once
#include "StarFormattedJson.hpp"
#include "StarJsonPath.hpp"
namespace Star {
struct GetCommand {
JsonPath::PathPtr path;
bool opt;
bool children;
};
struct SetCommand {
JsonPath::PathPtr path;
FormattedJson value;
};
struct AddCommand {
JsonPath::PathPtr path;
FormattedJson value;
};
struct RemoveCommand {
JsonPath::PathPtr path;
};
struct EditCommand {
JsonPath::PathPtr path;
};
typedef MVariant<GetCommand, SetCommand, AddCommand, RemoveCommand, EditCommand> Command;
struct AtBeginning {};
struct AtEnd {};
struct BeforeKey {
String key;
};
struct AfterKey {
String key;
};
typedef MVariant<AtBeginning, AtEnd, BeforeKey, AfterKey> InsertLocation;
STAR_CLASS(JsonInputFormat);
class JsonInputFormat {
public:
virtual ~JsonInputFormat() {}
virtual FormattedJson toJson(String const& input) const = 0;
virtual String fromJson(FormattedJson const& json) const = 0;
virtual FormattedJson getDefault() const = 0;
};
class GenericInputFormat : public JsonInputFormat {
public:
virtual FormattedJson toJson(String const& input) const override;
virtual String fromJson(FormattedJson const& json) const override;
virtual FormattedJson getDefault() const override;
};
class CommaSeparatedStrings : public JsonInputFormat {
public:
virtual FormattedJson toJson(String const& input) const override;
virtual String fromJson(FormattedJson const& json) const override;
virtual FormattedJson getDefault() const override;
};
class StringInputFormat : public JsonInputFormat {
public:
virtual FormattedJson toJson(String const& input) const override;
virtual String fromJson(FormattedJson const& json) const override;
virtual FormattedJson getDefault() const override;
};
STAR_CLASS(Output);
class Output {
public:
virtual ~Output() {}
virtual void out(FormattedJson const& json) = 0;
virtual void flush() = 0;
function<void(FormattedJson const& json)> toFunction() {
return [this](FormattedJson const& json) { this->out(json); };
}
};
class OutputOnSeparateLines : public Output {
public:
virtual void out(FormattedJson const& json) override;
virtual void flush() override;
};
class ArrayOutput : public Output {
public:
ArrayOutput(bool unique) : m_unique(unique), m_results() {}
virtual void out(FormattedJson const& json) override;
virtual void flush() override;
private:
bool m_unique;
List<FormattedJson> m_results;
};
struct Options {
Options() : inPlace(false), insertLocation(), editFormat(nullptr), editorImages(), output() {}
bool inPlace;
InsertLocation insertLocation;
JsonInputFormatPtr editFormat;
List<JsonPath::PathPtr> editorImages;
OutputPtr output;
};
struct JsonLiteralInput {
String json;
};
struct FileInput {
String filename;
};
struct FindInput {
String directory;
String filenameSuffix;
};
typedef MVariant<JsonLiteralInput, FileInput, FindInput> Input;
struct ParsedArgs {
ParsedArgs() : inputs(), command(), options() {}
List<Input> inputs;
Command command;
Options options;
};
FormattedJson addOrSet(bool add, JsonPath::PathPtr path, FormattedJson const& input, InsertLocation insertLocation, FormattedJson const& value);
String reprWithLineEnding(FormattedJson const& json);
StringList findFiles(FindInput const& findArgs);
}
|