VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Command.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "Types.h"
16#include <functional>
17#include <vector>
18#include <stack>
19
20namespace vc64 {
21
22class RetroShell;
23
24typedef std::vector<string> Arguments;
25
28namespace Arg {
29
30static const std::string address = "<address>";
31static const std::string boolean = "{ true | false }";
32static const std::string command = "<command>";
33static const std::string dst = "<destination>";
34static const std::string ignores = "<ignores>";
35static const std::string kb = "<kb>";
36static const std::string nr = "<nr>";
37static const std::string onoff = "{ on | off }";
38static const std::string path = "<path>";
39static const std::string process = "<process>";
40static const std::string seconds = "<seconds>";
41static const std::string value = "<value>";
42static const std::string count = "<count>";
43static const std::string sequence = "<byte sequence>";
44static const std::string src = "<source>";
45static const std::string volume = "<volume>";
46static const std::string string = "<string>";
47
48};
49
50struct Command {
51
52 // Textual descriptions of all command groups
53 static std::vector<string> groups;
54
55 // Group stack
56 static std::stack<isize> groupStack;
57
58 // Group of this command
59 isize group;
60
61 // Name of this command (e.g., "eject")
62 string name;
63
64 // Full name of this command (e.g., "df0 eject")
65 string fullName;
66
67 // Help description for this command
68 std::pair<string, string> help;
69
70 // List of required arguments
71 std::vector<string> requiredArgs;
72
73 // List of optional arguments
74 std::vector<string> optionalArgs;
75
76 // List of subcommands
77 std::vector<Command> subCommands;
78
79 // Command handler
80 std::function<void (Arguments&, long)> callback = nullptr;
81
82 // Additional argument passed to the command handler
83 long param = 0;
84
85 // Indicates if this command appears in help descriptions
86 bool hidden = false;
87
88
89 //
90 // Methods
91 //
92
93 // Begins or ends a command group
94 void pushGroup(const string &description, const string &postfix = ":");
95 void popGroup();
96
97 // Creates a new node in the command tree
98 void add(const std::vector<string> &tokens,
99 const string &help,
100 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
101
102 void add(const std::vector<string> &tokens,
103 std::pair<const string &, const string &> help,
104 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
105
106 void add(const std::vector<string> &tokens,
107 const std::vector<string> &args,
108 const string &help,
109 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
110
111 void add(const std::vector<string> &tokens,
112 const std::vector<string> &args,
113 std::pair<const string &, const string &> help,
114 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
115
116 void add(const std::vector<string> &tokens,
117 const std::vector<string> &requiredArgs,
118 const std::vector<string> &optionalArgs,
119 const string &help,
120 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
121
122 void add(const std::vector<string> &tokens,
123 const std::vector<string> &requiredArgs,
124 const std::vector<string> &optionalArgs,
125 std::pair<const string &, const string &> help,
126 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
127
128 void clone(const string &alias,
129 const std::vector<string> &tokens,
130 long param = 0);
131
132 void clone(const string &alias,
133 const std::vector<string> &tokens,
134 const string &help,
135 long param = 0);
136
137 /*
138 void registerSetCommand(const string &cmd, const ConfigOptions &options,
139 std::function<void (Arguments&, long)> func = nullptr, long param = 0);
140 */
141
142 // Returns arguments counts
143 isize minArgs() const { return isize(requiredArgs.size()); }
144 isize optArgs() const { return isize(optionalArgs.size()); }
145 isize maxArgs() const { return minArgs() + optArgs(); }
146
147 // Seeks a command object inside the command object tree
148 const Command *seek(const string& token) const;
149 Command *seek(const string& token);
150 const Command *seek(const std::vector<string> &tokens) const;
151 Command *seek(const std::vector<string> &tokens);
152
153 // Filters the argument list (used by auto-completion)
154 std::vector<const Command *> filterPrefix(const string& prefix) const;
155
156 // Automatically completes a partial token string
157 string autoComplete(const string& token);
158
159 // Returns a syntax string for this command
160 string usage() const;
161};
162
163}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16