chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
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
//            Copyright Keysight Technologies 2012-2019
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
using System;
 
namespace OpenTap.Cli
{
    /// <summary>
    /// When used on a property inside a <see cref="ICliAction"/>, this attribute indicates a command line arugment or switch.
    /// </summary>
    /// <remarks>
    /// The property type can be: bool, string, or string[]. If it's bool the argument will not take an argument, but will instead set the property to true.
    /// If it's a string the value of the property will be set to the first occuring value set in the CLI arguments.
    /// If it's a string[] all values set in the CLI arguments will be concatenated into an array.
    /// </remarks>
    [AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class CommandLineArgumentAttribute : Attribute
    {
        /// <summary>
        /// Indicates the long name of the command line argument.
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// Indicates the short name of the argument. This should be 1 character.
        /// </summary>
        public string ShortName { get; set; }
        /// <summary>
        /// Human readable description of the argument.
        /// </summary>
        public string Description { get; set; }
 
        /// <summary>
        /// Indicates whether this will be shown when writing CLI usage information.
        /// </summary>
        [Obsolete("Please use the 'Browsable' attribute.")]
        public bool Visible { get; set; } = true;
 
        /// <summary>
        /// Primary constructor.
        /// </summary>
        /// <param name="name">Long name of the argument.</param>
        public CommandLineArgumentAttribute(string name)
        {
            this.Name = name;
            ShortName = null;
            Description = null;
        }
    }
 
    /// <summary>
    /// Used on properties of a <see cref="ICliAction"/> to define an unnamed arguments on the CLI. These can be ordered to handle cases where some values are required and others can occur multiple times.
    /// The property type will indicate how many will be consumed. The type can be either string or string[]. In case of string[] all the remaining arguments will be assigned to this property.
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = true)]
    public class UnnamedCommandLineArgument : Attribute
    {
        /// <summary>
        /// Order or the arguments. The lowest value comes first.
        /// </summary>
        public int Order { get; set; }
        /// <summary>
        /// The name of the property. This will be shown in the CLI usage output.
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// Indicates whether this argument is required or optional. If it's a string[] and required then this indicates that it needs at least one value.
        /// </summary>
        public bool Required { get; set; }
 
        /// <summary>
        /// Human readable description of the argument.
        /// </summary>
        public string Description { get; set; }
 
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="name"></param>
        public UnnamedCommandLineArgument(string name)
        {
            this.Name = name;
            Order = 0;
            Required = false;
        }
    }
}