iceoryx2-cli 0.9.1

CLI tools for iceoryx2
Documentation
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
// Copyright (c) 2024 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache Software License 2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
// which is available at https://opensource.org/licenses/MIT.
//
// SPDX-License-Identifier: Apache-2.0 OR MIT

use clap::Args;
use clap::Parser;
use clap::Subcommand;
use clap::ValueEnum;

use iceoryx2_cli::Format;
use iceoryx2_cli::filter::MessagingPatternFilter;
use iceoryx2_cli::help_template;

#[derive(Parser)]
#[command(
    name = "iox2 service",
    bin_name = "iox2 service",
    about = "Query information about iceoryx2 services",
    long_about = None,
    version = env!("CARGO_PKG_VERSION"),
    disable_help_subcommand = true,
    arg_required_else_help = false,
    help_template = help_template().with_subcommands().build(),
)]
pub struct Cli {
    #[clap(subcommand)]
    pub action: Option<Action>,

    #[clap(long, short = 'f', value_enum, global = true, value_enum, default_value_t = Format::Ron)]
    pub format: Format,
}

#[derive(Debug, Clone, Args)]
pub struct OutputFilter {
    #[clap(short, long, value_enum, default_value_t = MessagingPatternFilter::All)]
    pub pattern: MessagingPatternFilter,
}

#[derive(Args)]
pub struct ListOptions {
    #[command(flatten)]
    pub filter: OutputFilter,
}

#[derive(Parser)]
pub struct DetailsOptions {
    #[clap(help = "Name of the service e.g. \"My Service\"")]
    pub service: String,

    #[command(flatten)]
    pub filter: OutputFilter,
}

#[derive(Parser)]
pub struct DiscoveryOptions {
    #[clap(
        short,
        long,
        default_value = "100",
        help = "Update rate in milliseconds"
    )]
    pub rate: u64,

    #[clap(long, help = "Show detailed information about discovered services")]
    pub detailed: bool,

    #[clap(long, help = "Do not publish discovered services")]
    pub disable_publish: bool,

    #[clap(long, default_value = "10", help = "The maximum number of subscribers")]
    pub max_subscribers: usize,

    #[clap(long, help = "Do not notify of discovered services")]
    pub disable_notify: bool,

    #[clap(long, default_value = "10", help = "The maximum number of listeners")]
    pub max_listeners: usize,
}

#[derive(Parser)]
pub struct NotifyOptions {
    #[clap(help = "Name of the service which shall be notified.")]
    pub service: String,
    #[clap(
        short,
        long,
        default_value = "0",
        help = "EventId value used for the notification."
    )]
    pub event_id: usize,
    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-notifier",
        help = "Defines the node name of the notification endpoint."
    )]
    pub node_name: String,
    #[clap(
        short = 'u',
        long,
        default_value = "1",
        help = "How often shall the notification be sent."
    )]
    pub num: u64,
    #[clap(
        short,
        long,
        default_value = "250",
        help = "Interval between notifications."
    )]
    pub interval_in_ms: u64,
}

#[derive(Parser)]
pub struct ListenOptions {
    #[clap(help = "Name of the service which shall be waited on for a notification.")]
    pub service: String,
    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-listener",
        help = "Defines the node name of the listening endpoint."
    )]
    pub node_name: String,
    #[clap(
        short,
        long,
        default_value = "1000",
        help = "Maximum delay between two notifications. Set to 0 to wait indefinitely."
    )]
    pub timeout_in_ms: u64,
    #[clap(
        short,
        long,
        help = "[Optional] How often shall the notification receive loop be repeated. If its not specified the call will listen indefinitely."
    )]
    pub repetitions: Option<u64>,
}

#[derive(Clone, Copy, ValueEnum)]
#[value(rename_all = "UPPERCASE")]
pub enum CliTypeVariant {
    Dynamic,
    FixedSize,
}

#[derive(Clone, Copy, ValueEnum, Default)]
#[value(rename_all = "UPPERCASE")]
pub enum DataRepresentation {
    Iox2Dump,
    #[default]
    HumanReadable,
}

impl From<DataRepresentation> for iceoryx2_userland_record_and_replay::record::DataRepresentation {
    fn from(value: DataRepresentation) -> Self {
        match value {
            DataRepresentation::HumanReadable => {
                iceoryx2_userland_record_and_replay::record::DataRepresentation::HumanReadable
            }
            DataRepresentation::Iox2Dump => {
                iceoryx2_userland_record_and_replay::record::DataRepresentation::Iox2Dump
            }
        }
    }
}

#[derive(Clone, Copy, ValueEnum, Default)]
#[value(rename_all = "UPPERCASE")]
pub enum MessagingPattern {
    #[default]
    PublishSubscribe,
}

impl From<MessagingPattern> for iceoryx2::prelude::MessagingPattern {
    fn from(value: MessagingPattern) -> Self {
        match value {
            MessagingPattern::PublishSubscribe => {
                iceoryx2::prelude::MessagingPattern::PublishSubscribe
            }
        }
    }
}

#[derive(Parser)]
pub struct PublishOptions {
    #[clap(help = "Name of the service which the message shall be sent to.")]
    pub service: String,
    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-publisher",
        help = "Defines the node name of the publish endpoint."
    )]
    pub node_name: String,
    #[clap(
        short,
        long,
        help = "The messages that shall be sent. Can be multiple messages. If no messages are given stdin is read."
    )]
    pub message: Vec<String>,

    #[clap(
        short,
        long,
        default_value = "1000",
        help = "Time between the messages in milliseconds."
    )]
    pub time_between_messages: usize,

    #[clap(
        short,
        long,
        default_value = "HUMANREADABLE",
        help = "Defines how the provided data is encoded."
    )]
    pub data_representation: DataRepresentation,

    #[clap(
        short,
        long,
        default_value = "1",
        help = "How often shall the messages be sent. If `0` is set the messages will be sent indefinitely."
    )]
    pub repetitions: usize,

    #[clap(
        long,
        default_value = "4096",
        help = "It defines the initial payload size for dynamic type variants."
    )]
    pub initial_payload_size: usize,

    #[clap(
        long,
        default_value = "u8",
        help = "Defines the unique type identifier of the services type."
    )]
    pub type_name: String,
    #[clap(
        long,
        default_value = "1",
        help = "Defines the type size of the services type."
    )]
    pub type_size: usize,
    #[clap(
        long,
        default_value = "1",
        help = "Defines the type alignment of the services type."
    )]
    pub type_alignment: usize,
    #[clap(long, default_value = "DYNAMIC", help = "Defines variant.")]
    pub type_variant: CliTypeVariant,

    #[clap(
        long,
        default_value = "()",
        help = "Defines the unique type identifier of the services user header type."
    )]
    pub header_type_name: String,
    #[clap(
        long,
        default_value = "0",
        help = "Defines the type size of the services user header type."
    )]
    pub header_type_size: usize,
    #[clap(
        long,
        default_value = "1",
        help = "Defines the type alignment of the services user header type."
    )]
    pub header_type_alignment: usize,
}

#[derive(Parser)]
pub struct SubscribeOptions {
    #[clap(help = "Name of the service which shall be waited on for a message.")]
    pub service: String,
    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-subscriber",
        help = "Defines the node name of the subscriber endpoint."
    )]
    pub node_name: String,

    #[clap(
        short,
        long,
        default_value = "HUMANREADABLE",
        help = "Defines how the data shall be displayed."
    )]
    pub data_representation: DataRepresentation,

    #[clap(
        short,
        long,
        help = "Maximum runtime in milliseconds. When the timeout has passed the process stops."
    )]
    pub timeout: Option<u64>,

    #[clap(
        short,
        long,
        help = "Maximum number of messages to be received before the process stops."
    )]
    pub max_messages: Option<u64>,
}

#[derive(Parser)]
pub struct RecordOptions {
    #[clap(help = "Name of the service which shall be recorded.")]
    pub service: String,

    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-recorder",
        help = "Defines the node name of the recorder endpoint."
    )]
    pub node_name: String,

    #[clap(
        short,
        long,
        help = "Non-existing file which will be created and the captured records will be stored."
    )]
    pub output: String,

    #[clap(
        short,
        long,
        default_value = "1",
        help = "Cycle time that defines how long the recorder will wait before polling for further messages."
    )]
    pub cycle_time_in_ms: u64,

    #[clap(
        short,
        long,
        default_value = "HUMANREADABLE",
        help = "Defines the data format of the recorded file."
    )]
    pub data_representation: DataRepresentation,

    #[clap(
        short,
        long,
        default_value = "PUBLISHSUBSCRIBE",
        help = "Defines the messaging pattern of the service."
    )]
    pub messaging_pattern: MessagingPattern,

    #[clap(
        short,
        long,
        help = "Maximum runtime in seconds. When the timeout has passed the recorder stops."
    )]
    pub timeout_in_sec: Option<u64>,

    #[clap(
        long,
        help = "Maximum number of messages to be received before the recorder stops."
    )]
    pub max_messages: Option<u64>,
}

#[derive(Parser)]
pub struct HzOptions {
    #[clap(help = "Name of the service to measure the message frequency of.")]
    pub service: String,
    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-hz",
        help = "Defines the node name of the hz measurement endpoint."
    )]
    pub node_name: String,
    #[clap(
        short,
        long,
        default_value = "10000",
        help = "Rolling window size, in # of messages, for calculating rate (default: 10000)."
    )]
    pub window: usize,
    #[clap(
        short,
        long,
        help = "Maximum runtime in seconds. When the timeout has passed the process stops."
    )]
    pub timeout: Option<u64>,
}

#[derive(Parser)]
pub struct ReplayOptions {
    #[clap(help = "When provided, it overrides the service name of the record file.")]
    pub service: Option<String>,

    #[clap(
        short,
        long,
        default_value = "iox2-cli-service-replayer",
        help = "Defines the node name of the replayer endpoint."
    )]
    pub node_name: String,

    #[clap(short, long, help = "The file that contains the recorded data.")]
    pub input: String,

    #[clap(
        short,
        long,
        default_value = "HUMANREADABLE",
        help = "Defines how the data in the file is encoded."
    )]
    pub data_representation: DataRepresentation,

    #[clap(
        short,
        long,
        default_value = "PUBLISHSUBSCRIBE",
        help = "Defines the messaging pattern of the service."
    )]
    pub messaging_pattern: MessagingPattern,

    #[clap(
        short,
        long,
        default_value = "1",
        help = "How often the recorded data shall be sent repeatedly."
    )]
    pub repetitions: u64,

    #[clap(
        short,
        long,
        default_value = "1.0",
        help = "The timings in the file will be multiplied by the given factor to increase or slow down the playback."
    )]
    pub time_factor: f32,
}

#[derive(Subcommand)]
pub enum Action {
    #[clap(
        about = "List all services",
        help_template = help_template().build()
    )]
    List(ListOptions),
    #[clap(
        about = "Show service details",
        help_template = help_template().with_positionals().build()
    )]
    Details(DetailsOptions),
    #[clap(
        about = "Runs the service discovery service within a process",
        help_template = help_template().build()
    )]
    Discovery(DiscoveryOptions),
    #[clap(
        about = "Send a notification",
        help_template = help_template().with_positionals().build()
    )]
    Notify(NotifyOptions),
    #[clap(
        about = "Wait until a notification arrives",
        help_template = help_template().with_positionals().build()
    )]
    Listen(ListenOptions),
    #[clap(
        about = "Publish a message to any service.",
        help_template = help_template().with_positionals().build()
    )]
    Publish(PublishOptions),
    #[clap(
        about = "Subscribe to any service and introspect its messages.",
        help_template = help_template().with_positionals().build()
    )]
    Subscribe(SubscribeOptions),
    #[clap(
        about = "Record data from any service.",
        help_template = help_template().with_positionals().build()
    )]
    Record(RecordOptions),
    #[clap(
        about = "Replay pre-recorded data to any service.",
        help_template = help_template().with_positionals().build()
    )]
    Replay(ReplayOptions),
    #[clap(
        about = "Measure the message frequency (Hz) of a publish-subscribe service.",
        help_template = help_template().with_positionals().build()
    )]
    Hz(HzOptions),
}