docker-wrapper 0.11.1

A Docker CLI wrapper for Rust
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
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
//! Docker info command implementation
//!
//! This module provides functionality to retrieve Docker system information,
//! including daemon configuration, storage details, and runtime information.

use super::{CommandExecutor, CommandOutput, DockerCommand};
use crate::error::{Error, Result};
use async_trait::async_trait;
use std::fmt;

/// Command for retrieving Docker system information
///
/// The `InfoCommand` provides a builder pattern for constructing Docker info commands
/// with various output format options.
///
/// # Examples
///
/// ```rust
/// use docker_wrapper::InfoCommand;
///
/// // Basic system info
/// let info = InfoCommand::new();
///
/// // JSON format output
/// let info = InfoCommand::new().format_json();
///
/// // Custom format
/// let info = InfoCommand::new()
///     .format("{{.ServerVersion}}");
/// ```
#[derive(Debug, Clone)]
pub struct InfoCommand {
    /// Output format
    format: Option<String>,
    /// Command executor for running the command
    pub executor: CommandExecutor,
}

/// Docker system information
#[derive(Debug, Clone, PartialEq)]
pub struct SystemInfo {
    /// Docker server version
    pub server_version: String,
    /// Storage driver in use
    pub storage_driver: String,
    /// Logging driver
    pub logging_driver: String,
    /// Cgroup driver
    pub cgroup_driver: String,
    /// Cgroup version
    pub cgroup_version: String,
    /// Number of containers
    pub containers: u32,
    /// Number of running containers
    pub containers_running: u32,
    /// Number of paused containers
    pub containers_paused: u32,
    /// Number of stopped containers
    pub containers_stopped: u32,
    /// Number of images
    pub images: u32,
    /// Docker root directory
    pub docker_root_dir: String,
    /// Debug mode enabled
    pub debug: bool,
    /// Experimental features enabled
    pub experimental: bool,
    /// Total memory
    pub mem_total: u64,
    /// Number of CPUs
    pub ncpu: u32,
    /// Operating system
    pub operating_system: String,
    /// OS type
    pub os_type: String,
    /// Architecture
    pub architecture: String,
    /// Kernel version
    pub kernel_version: String,
    /// Name (hostname)
    pub name: String,
    /// Docker daemon ID
    pub id: String,
}

/// Docker registry configuration
#[derive(Debug, Clone, PartialEq)]
pub struct RegistryConfig {
    /// Insecure registries
    pub insecure_registries: Vec<String>,
    /// Index configs
    pub index_configs: Vec<String>,
    /// Mirrors
    pub mirrors: Vec<String>,
}

/// Docker runtime information
#[derive(Debug, Clone, PartialEq)]
pub struct RuntimeInfo {
    /// Default runtime
    pub default_runtime: String,
    /// Available runtimes
    pub runtimes: Vec<String>,
}

/// Complete Docker system information
#[derive(Debug, Clone, PartialEq)]
pub struct DockerInfo {
    /// Basic system information
    pub system: SystemInfo,
    /// Registry configuration
    pub registry: Option<RegistryConfig>,
    /// Runtime information
    pub runtime: Option<RuntimeInfo>,
    /// Warnings from the Docker daemon
    pub warnings: Vec<String>,
}

/// Output from an info command execution
///
/// Contains the raw output from the Docker info command and provides
/// convenience methods for parsing system information.
#[derive(Debug, Clone)]
pub struct InfoOutput {
    /// Raw output from the Docker command
    pub output: CommandOutput,
    /// Parsed Docker information
    pub docker_info: Option<DockerInfo>,
}

impl InfoCommand {
    /// Creates a new info command
    ///
    /// # Examples
    ///
    /// ```rust
    /// use docker_wrapper::InfoCommand;
    ///
    /// let info = InfoCommand::new();
    /// ```
    #[must_use]
    pub fn new() -> Self {
        Self {
            format: None,
            executor: CommandExecutor::default(),
        }
    }

    /// Sets the output format
    ///
    /// # Arguments
    ///
    /// * `format` - Output format string or template
    ///
    /// # Examples
    ///
    /// ```rust
    /// use docker_wrapper::InfoCommand;
    ///
    /// let info = InfoCommand::new()
    ///     .format("{{.ServerVersion}}");
    /// ```
    #[must_use]
    pub fn format(mut self, format: impl Into<String>) -> Self {
        self.format = Some(format.into());
        self
    }

    /// Sets output format to JSON
    ///
    /// # Examples
    ///
    /// ```rust
    /// use docker_wrapper::InfoCommand;
    ///
    /// let info = InfoCommand::new().format_json();
    /// ```
    #[must_use]
    pub fn format_json(self) -> Self {
        self.format("json")
    }

    /// Sets output format to table (default)
    #[must_use]
    pub fn format_table(self) -> Self {
        Self {
            format: None,
            executor: self.executor,
        }
    }

    /// Gets the command executor
    #[must_use]
    pub fn get_executor(&self) -> &CommandExecutor {
        &self.executor
    }

    /// Gets the command executor mutably
    pub fn get_executor_mut(&mut self) -> &mut CommandExecutor {
        &mut self.executor
    }

    /// Builds the command arguments for Docker info
    #[must_use]
    pub fn build_command_args(&self) -> Vec<String> {
        let mut args = vec!["info".to_string()];

        // Add format option
        if let Some(ref format) = self.format {
            args.push("--format".to_string());
            args.push(format.clone());
        }

        // Add any additional raw arguments
        args.extend(self.executor.raw_args.clone());

        args
    }

    /// Parses the info output
    fn parse_output(&self, output: &CommandOutput) -> Result<Option<DockerInfo>> {
        if let Some(ref format) = self.format {
            if format == "json" {
                return Self::parse_json_output(output);
            }
        }

        Ok(Self::parse_table_output(output))
    }

    /// Parses JSON formatted info output
    fn parse_json_output(output: &CommandOutput) -> Result<Option<DockerInfo>> {
        let parsed: serde_json::Value = serde_json::from_str(&output.stdout)
            .map_err(|e| Error::parse_error(format!("Failed to parse info JSON output: {e}")))?;

        let system = SystemInfo {
            server_version: parsed["ServerVersion"].as_str().unwrap_or("").to_string(),
            storage_driver: parsed["Driver"].as_str().unwrap_or("").to_string(),
            logging_driver: parsed["LoggingDriver"].as_str().unwrap_or("").to_string(),
            cgroup_driver: parsed["CgroupDriver"].as_str().unwrap_or("").to_string(),
            cgroup_version: parsed["CgroupVersion"].as_str().unwrap_or("").to_string(),
            containers: u32::try_from(parsed["Containers"].as_u64().unwrap_or(0)).unwrap_or(0),
            containers_running: u32::try_from(parsed["ContainersRunning"].as_u64().unwrap_or(0))
                .unwrap_or(0),
            containers_paused: u32::try_from(parsed["ContainersPaused"].as_u64().unwrap_or(0))
                .unwrap_or(0),
            containers_stopped: u32::try_from(parsed["ContainersStopped"].as_u64().unwrap_or(0))
                .unwrap_or(0),
            images: u32::try_from(parsed["Images"].as_u64().unwrap_or(0)).unwrap_or(0),
            docker_root_dir: parsed["DockerRootDir"].as_str().unwrap_or("").to_string(),
            debug: parsed["Debug"].as_bool().unwrap_or(false),
            experimental: parsed["ExperimentalBuild"].as_bool().unwrap_or(false),
            mem_total: parsed["MemTotal"].as_u64().unwrap_or(0),
            ncpu: u32::try_from(parsed["NCPU"].as_u64().unwrap_or(0)).unwrap_or(0),
            operating_system: parsed["OperatingSystem"].as_str().unwrap_or("").to_string(),
            os_type: parsed["OSType"].as_str().unwrap_or("").to_string(),
            architecture: parsed["Architecture"].as_str().unwrap_or("").to_string(),
            kernel_version: parsed["KernelVersion"].as_str().unwrap_or("").to_string(),
            name: parsed["Name"].as_str().unwrap_or("").to_string(),
            id: parsed["ID"].as_str().unwrap_or("").to_string(),
        };

        // Parse registry config
        let registry = parsed.get("RegistryConfig").map(|registry_data| {
            let insecure_registries = registry_data["InsecureRegistryCIDRs"]
                .as_array()
                .map(|arr| {
                    arr.iter()
                        .filter_map(|v| v.as_str())
                        .map(String::from)
                        .collect()
                })
                .unwrap_or_default();

            let index_configs = registry_data["IndexConfigs"]
                .as_object()
                .map(|obj| obj.keys().map(String::from).collect())
                .unwrap_or_default();

            let mirrors = registry_data["Mirrors"]
                .as_array()
                .map(|arr| {
                    arr.iter()
                        .filter_map(|v| v.as_str())
                        .map(String::from)
                        .collect()
                })
                .unwrap_or_default();

            RegistryConfig {
                insecure_registries,
                index_configs,
                mirrors,
            }
        });

        // Parse runtime info
        let runtime = parsed.get("Runtimes").map(|runtimes_data| {
            let default_runtime = parsed["DefaultRuntime"].as_str().unwrap_or("").to_string();

            let runtimes = runtimes_data
                .as_object()
                .map(|obj| obj.keys().map(String::from).collect())
                .unwrap_or_default();

            RuntimeInfo {
                default_runtime,
                runtimes,
            }
        });

        // Parse warnings
        let warnings = parsed["Warnings"]
            .as_array()
            .map(|arr| {
                arr.iter()
                    .filter_map(|v| v.as_str())
                    .map(String::from)
                    .collect()
            })
            .unwrap_or_default();

        Ok(Some(DockerInfo {
            system,
            registry,
            runtime,
            warnings,
        }))
    }

    /// Parses table formatted info output
    fn parse_table_output(output: &CommandOutput) -> Option<DockerInfo> {
        let lines: Vec<&str> = output.stdout.lines().collect();

        if lines.is_empty() {
            return None;
        }

        let mut data = std::collections::HashMap::new();
        let mut warnings = Vec::new();

        for line in lines {
            let trimmed = line.trim();

            if trimmed.is_empty() {
                continue;
            }

            // Check for warnings
            if trimmed.starts_with("WARNING:") {
                warnings.push(trimmed.to_string());
                continue;
            }

            // Parse key-value pairs
            if let Some(colon_pos) = trimmed.find(':') {
                let key = trimmed[..colon_pos].trim();
                let value = trimmed[colon_pos + 1..].trim();
                data.insert(key.to_string(), value.to_string());
            }
        }

        let system = SystemInfo {
            server_version: data.get("Server Version").cloned().unwrap_or_default(),
            storage_driver: data.get("Storage Driver").cloned().unwrap_or_default(),
            logging_driver: data.get("Logging Driver").cloned().unwrap_or_default(),
            cgroup_driver: data.get("Cgroup Driver").cloned().unwrap_or_default(),
            cgroup_version: data.get("Cgroup Version").cloned().unwrap_or_default(),
            containers: data
                .get("Containers")
                .and_then(|s| s.parse().ok())
                .unwrap_or(0),
            containers_running: data
                .get("Running")
                .and_then(|s| s.parse().ok())
                .unwrap_or(0),
            containers_paused: data.get("Paused").and_then(|s| s.parse().ok()).unwrap_or(0),
            containers_stopped: data
                .get("Stopped")
                .and_then(|s| s.parse().ok())
                .unwrap_or(0),
            images: data.get("Images").and_then(|s| s.parse().ok()).unwrap_or(0),
            docker_root_dir: data.get("Docker Root Dir").cloned().unwrap_or_default(),
            debug: data.get("Debug Mode").is_some_and(|s| s == "true"),
            experimental: data.get("Experimental").is_some_and(|s| s == "true"),
            mem_total: data
                .get("Total Memory")
                .and_then(|s| s.split_whitespace().next())
                .and_then(|s| s.parse().ok())
                .unwrap_or(0),
            ncpu: data.get("CPUs").and_then(|s| s.parse().ok()).unwrap_or(0),
            operating_system: data.get("Operating System").cloned().unwrap_or_default(),
            os_type: data.get("OSType").cloned().unwrap_or_default(),
            architecture: data.get("Architecture").cloned().unwrap_or_default(),
            kernel_version: data.get("Kernel Version").cloned().unwrap_or_default(),
            name: data.get("Name").cloned().unwrap_or_default(),
            id: data.get("ID").cloned().unwrap_or_default(),
        };

        Some(DockerInfo {
            system,
            registry: None, // Not easily parseable from table format
            runtime: None,  // Not easily parseable from table format
            warnings,
        })
    }

    /// Gets the output format (if set)
    #[must_use]
    pub fn get_format(&self) -> Option<&str> {
        self.format.as_deref()
    }
}

impl Default for InfoCommand {
    fn default() -> Self {
        Self::new()
    }
}

impl InfoOutput {
    /// Returns true if the info command was successful
    #[must_use]
    pub fn success(&self) -> bool {
        self.output.success
    }

    /// Gets the Docker server version
    #[must_use]
    pub fn server_version(&self) -> Option<&str> {
        self.docker_info
            .as_ref()
            .map(|info| info.system.server_version.as_str())
    }

    /// Gets the storage driver
    #[must_use]
    pub fn storage_driver(&self) -> Option<&str> {
        self.docker_info
            .as_ref()
            .map(|info| info.system.storage_driver.as_str())
    }

    /// Gets the total number of containers
    #[must_use]
    pub fn container_count(&self) -> u32 {
        self.docker_info
            .as_ref()
            .map_or(0, |info| info.system.containers)
    }

    /// Gets the number of running containers
    #[must_use]
    pub fn running_containers(&self) -> u32 {
        self.docker_info
            .as_ref()
            .map_or(0, |info| info.system.containers_running)
    }

    /// Gets the number of images
    #[must_use]
    pub fn image_count(&self) -> u32 {
        self.docker_info
            .as_ref()
            .map_or(0, |info| info.system.images)
    }

    /// Returns true if debug mode is enabled
    #[must_use]
    pub fn is_debug(&self) -> bool {
        self.docker_info
            .as_ref()
            .is_some_and(|info| info.system.debug)
    }

    /// Returns true if experimental features are enabled
    #[must_use]
    pub fn is_experimental(&self) -> bool {
        self.docker_info
            .as_ref()
            .is_some_and(|info| info.system.experimental)
    }

    /// Gets the operating system
    #[must_use]
    pub fn operating_system(&self) -> Option<&str> {
        self.docker_info
            .as_ref()
            .map(|info| info.system.operating_system.as_str())
    }

    /// Gets the architecture
    #[must_use]
    pub fn architecture(&self) -> Option<&str> {
        self.docker_info
            .as_ref()
            .map(|info| info.system.architecture.as_str())
    }

    /// Gets any warnings from the Docker daemon
    #[must_use]
    pub fn warnings(&self) -> Vec<&str> {
        self.docker_info
            .as_ref()
            .map(|info| info.warnings.iter().map(String::as_str).collect())
            .unwrap_or_default()
    }

    /// Returns true if there are any warnings
    #[must_use]
    pub fn has_warnings(&self) -> bool {
        self.docker_info
            .as_ref()
            .is_some_and(|info| !info.warnings.is_empty())
    }

    /// Gets system resource information (containers and images)
    #[must_use]
    pub fn resource_summary(&self) -> (u32, u32, u32) {
        if let Some(info) = &self.docker_info {
            (
                info.system.containers,
                info.system.containers_running,
                info.system.images,
            )
        } else {
            (0, 0, 0)
        }
    }
}

#[async_trait]
impl DockerCommand for InfoCommand {
    type Output = InfoOutput;

    fn get_executor(&self) -> &CommandExecutor {
        &self.executor
    }

    fn get_executor_mut(&mut self) -> &mut CommandExecutor {
        &mut self.executor
    }

    fn build_command_args(&self) -> Vec<String> {
        self.build_command_args()
    }

    async fn execute(&self) -> Result<Self::Output> {
        let args = self.build_command_args();
        let output = self.execute_command(args).await?;

        let docker_info = self.parse_output(&output)?;

        Ok(InfoOutput {
            output,
            docker_info,
        })
    }
}

impl fmt::Display for InfoCommand {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "docker info")?;

        if let Some(ref format) = self.format {
            write!(f, " --format {format}")?;
        }

        Ok(())
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_info_command_basic() {
        let info = InfoCommand::new();

        assert_eq!(info.get_format(), None);

        let args = info.build_command_args();
        assert_eq!(args, vec!["info"]);
    }

    #[test]
    fn test_info_command_with_format() {
        let info = InfoCommand::new().format("{{.ServerVersion}}");

        assert_eq!(info.get_format(), Some("{{.ServerVersion}}"));

        let args = info.build_command_args();
        assert_eq!(args, vec!["info", "--format", "{{.ServerVersion}}"]);
    }

    #[test]
    fn test_info_command_json_format() {
        let info = InfoCommand::new().format_json();

        assert_eq!(info.get_format(), Some("json"));

        let args = info.build_command_args();
        assert_eq!(args, vec!["info", "--format", "json"]);
    }

    #[test]
    fn test_info_command_table_format() {
        let info = InfoCommand::new().format_json().format_table();

        assert_eq!(info.get_format(), None);

        let args = info.build_command_args();
        assert_eq!(args, vec!["info"]);
    }

    #[test]
    fn test_info_command_default() {
        let info = InfoCommand::default();

        assert_eq!(info.get_format(), None);
        let args = info.build_command_args();
        assert_eq!(args, vec!["info"]);
    }

    #[test]
    fn test_system_info_creation() {
        let system = SystemInfo {
            server_version: "20.10.17".to_string(),
            storage_driver: "overlay2".to_string(),
            logging_driver: "json-file".to_string(),
            cgroup_driver: "systemd".to_string(),
            cgroup_version: "2".to_string(),
            containers: 10,
            containers_running: 3,
            containers_paused: 0,
            containers_stopped: 7,
            images: 25,
            docker_root_dir: "/var/lib/docker".to_string(),
            debug: false,
            experimental: false,
            mem_total: 8_589_934_592,
            ncpu: 8,
            operating_system: "Ubuntu 20.04.4 LTS".to_string(),
            os_type: "linux".to_string(),
            architecture: "x86_64".to_string(),
            kernel_version: "5.15.0-56-generic".to_string(),
            name: "docker-host".to_string(),
            id: "ABCD:1234:5678:90EF".to_string(),
        };

        assert_eq!(system.server_version, "20.10.17");
        assert_eq!(system.storage_driver, "overlay2");
        assert_eq!(system.containers, 10);
        assert_eq!(system.containers_running, 3);
        assert_eq!(system.images, 25);
        assert!(!system.debug);
        assert!(!system.experimental);
    }

    #[test]
    fn test_registry_config_creation() {
        let registry = RegistryConfig {
            insecure_registries: vec!["localhost:5000".to_string()],
            index_configs: vec!["https://index.docker.io/v1/".to_string()],
            mirrors: vec!["https://mirror.gcr.io".to_string()],
        };

        assert_eq!(registry.insecure_registries.len(), 1);
        assert_eq!(registry.index_configs.len(), 1);
        assert_eq!(registry.mirrors.len(), 1);
    }

    #[test]
    fn test_runtime_info_creation() {
        let runtime = RuntimeInfo {
            default_runtime: "runc".to_string(),
            runtimes: vec!["runc".to_string(), "nvidia".to_string()],
        };

        assert_eq!(runtime.default_runtime, "runc");
        assert_eq!(runtime.runtimes.len(), 2);
    }

    #[test]
    fn test_docker_info_creation() {
        let system = SystemInfo {
            server_version: "20.10.17".to_string(),
            storage_driver: "overlay2".to_string(),
            logging_driver: "json-file".to_string(),
            cgroup_driver: "systemd".to_string(),
            cgroup_version: "2".to_string(),
            containers: 5,
            containers_running: 2,
            containers_paused: 0,
            containers_stopped: 3,
            images: 10,
            docker_root_dir: "/var/lib/docker".to_string(),
            debug: true,
            experimental: true,
            mem_total: 8_589_934_592,
            ncpu: 4,
            operating_system: "Ubuntu 20.04".to_string(),
            os_type: "linux".to_string(),
            architecture: "x86_64".to_string(),
            kernel_version: "5.15.0".to_string(),
            name: "test-host".to_string(),
            id: "TEST:1234".to_string(),
        };

        let docker_info = DockerInfo {
            system,
            registry: None,
            runtime: None,
            warnings: vec!["Test warning".to_string()],
        };

        assert_eq!(docker_info.system.server_version, "20.10.17");
        assert_eq!(docker_info.warnings.len(), 1);
        assert!(docker_info.registry.is_none());
        assert!(docker_info.runtime.is_none());
    }

    #[test]
    fn test_info_output_helpers() {
        let system = SystemInfo {
            server_version: "20.10.17".to_string(),
            storage_driver: "overlay2".to_string(),
            logging_driver: "json-file".to_string(),
            cgroup_driver: "systemd".to_string(),
            cgroup_version: "2".to_string(),
            containers: 15,
            containers_running: 5,
            containers_paused: 1,
            containers_stopped: 9,
            images: 30,
            docker_root_dir: "/var/lib/docker".to_string(),
            debug: true,
            experimental: false,
            mem_total: 8_589_934_592,
            ncpu: 8,
            operating_system: "Ubuntu 22.04 LTS".to_string(),
            os_type: "linux".to_string(),
            architecture: "x86_64".to_string(),
            kernel_version: "5.15.0-56-generic".to_string(),
            name: "test-docker".to_string(),
            id: "TEST:ABCD:1234".to_string(),
        };

        let docker_info = DockerInfo {
            system,
            registry: None,
            runtime: None,
            warnings: vec![
                "WARNING: No swap limit support".to_string(),
                "WARNING: No memory limit support".to_string(),
            ],
        };

        let output = InfoOutput {
            output: CommandOutput {
                stdout: String::new(),
                stderr: String::new(),
                exit_code: 0,
                success: true,
            },
            docker_info: Some(docker_info),
        };

        assert_eq!(output.server_version(), Some("20.10.17"));
        assert_eq!(output.storage_driver(), Some("overlay2"));
        assert_eq!(output.container_count(), 15);
        assert_eq!(output.running_containers(), 5);
        assert_eq!(output.image_count(), 30);
        assert!(output.is_debug());
        assert!(!output.is_experimental());
        assert_eq!(output.operating_system(), Some("Ubuntu 22.04 LTS"));
        assert_eq!(output.architecture(), Some("x86_64"));
        assert!(output.has_warnings());
        assert_eq!(output.warnings().len(), 2);

        let (total, running, images) = output.resource_summary();
        assert_eq!(total, 15);
        assert_eq!(running, 5);
        assert_eq!(images, 30);
    }

    #[test]
    fn test_info_output_no_data() {
        let output = InfoOutput {
            output: CommandOutput {
                stdout: String::new(),
                stderr: String::new(),
                exit_code: 0,
                success: true,
            },
            docker_info: None,
        };

        assert_eq!(output.server_version(), None);
        assert_eq!(output.storage_driver(), None);
        assert_eq!(output.container_count(), 0);
        assert_eq!(output.running_containers(), 0);
        assert_eq!(output.image_count(), 0);
        assert!(!output.is_debug());
        assert!(!output.is_experimental());
        assert!(!output.has_warnings());
        assert_eq!(output.warnings().len(), 0);

        let (total, running, images) = output.resource_summary();
        assert_eq!(total, 0);
        assert_eq!(running, 0);
        assert_eq!(images, 0);
    }

    #[test]
    fn test_info_command_display() {
        let info = InfoCommand::new().format("{{.ServerVersion}}");

        let display = format!("{info}");
        assert_eq!(display, "docker info --format {{.ServerVersion}}");
    }

    #[test]
    fn test_info_command_display_no_format() {
        let info = InfoCommand::new();

        let display = format!("{info}");
        assert_eq!(display, "docker info");
    }

    #[test]
    fn test_info_command_name() {
        let info = InfoCommand::new();
        let args = info.build_command_args();
        assert_eq!(args[0], "info");
    }

    #[test]
    fn test_info_command_extensibility() {
        let mut info = InfoCommand::new();

        // Test that we can add custom raw arguments
        info.get_executor_mut()
            .raw_args
            .push("--verbose".to_string());
        info.get_executor_mut()
            .raw_args
            .push("--some-flag".to_string());

        let args = info.build_command_args();

        // Verify raw args are included
        assert!(args.contains(&"--verbose".to_string()));
        assert!(args.contains(&"--some-flag".to_string()));
    }

    #[test]
    fn test_parse_json_output_concept() {
        // This test demonstrates the concept of parsing JSON output
        let json_output = r#"{"ServerVersion":"20.10.17","Driver":"overlay2","Containers":5}"#;

        let output = CommandOutput {
            stdout: json_output.to_string(),
            stderr: String::new(),
            exit_code: 0,
            success: true,
        };

        let result = InfoCommand::parse_json_output(&output);

        // The actual parsing would need real Docker JSON output
        assert!(result.is_ok());
    }

    #[test]
    fn test_parse_table_output_concept() {
        // This test demonstrates the concept of parsing table output
        let table_output = "Server Version: 20.10.17\nStorage Driver: overlay2\nContainers: 5\nRunning: 2\nImages: 10\nWARNING: Test warning";

        let output = CommandOutput {
            stdout: table_output.to_string(),
            stderr: String::new(),
            exit_code: 0,
            success: true,
        };

        let result = InfoCommand::parse_table_output(&output);

        // The actual parsing would need real Docker table output
        assert!(result.is_some() || result.is_none());
    }
}