github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/res/en/sample.yaml (about)

     1  title: zendata config syntax
     2  desc:
     3  
     4    # File composition
     5  
     6      # zendata defines the format for each field in YAML file.
     7      # YAML file is composed of file description and field definition.
     8  
     9    # File description
    10  
    11      # title:   A short text to summarize the data type defined by this file.
    12      # desc:    Detailed text to describe the data type defined in this file, optional.
    13      # author:  Optional.
    14      # version: Version number, optional.
    15  
    16    # Field list
    17  
    18      # Field is defined in fields.
    19      # A YAML file contains one or more fields.
    20      # Field list starts from -field.
    21      # A child field can be defined by fields.
    22  
    23    # Field definition
    24  
    25      # field:    Field name; letters, digits, underlines and dots only.
    26      # range:    List range; the most important definition.
    27      # loop:     The number of loops; define how many times a field can loop.
    28      # loopfix:  The connector for each loop.
    29  
    30      # format:   Support formatted output.
    31  
    32      # prefix:   Prefix of this field.
    33      # postfix:  Postfix of this field.
    34  
    35      # length:   The length of this field. If separators are not used, specify the field length in bytes.
    36      # leftpad:  Left-padded characters. If the length is not enough, specify a character. The default is space.
    37      # rightpad: Right-padded characters. If the length is not enough, specify a character.
    38  
    39      # config:   Refer to the definition in other file.
    40  
    41      # from:     Refer to a definition file.
    42      # use:      Use instances defined in the referred file.
    43      # select:   If refer to an excel table, you can query a field in it.
    44      # where:    If refer to an excel table, you can use query conditions.
    45  
    46    # Loop Definition
    47  
    48      # Define the loop times of a field with a number, e.g. loop:2.
    49      # Define the loop times of a field with an interval, e.g. loop:2-10.
    50  
    51    # range definition
    52  
    53      # Use commas to connect elements. e.g. range: 1,2,3.
    54      # Elements can be a range, e.g. range:1-10, A-Z.
    55      # Use colons to define steps, e.g. range:1-10:2.
    56      # Steps can be decimals, e.g. range: 1-10:0.1.
    57      # Steps can be negative, e.g. range: 9-1:-1
    58      # Intervals can be set as random by R, e.g. range: 1-10:R. Set either random or a specified step.
    59      # Use a file to specify a list, e.g. range: list.txt. If the file name is a relative path, it is based on the config file.
    60      # Use {n} to repeat a element, e.g. range: user1{100},user2{100}.
    61      # Use [], if intervals and elements are repeated, e.g. range: [user1,user2,user3]{100}, [1-100]{10}.
    62  
    63  author: zentao
    64  version: 1.0
    65  
    66  fields:
    67  
    68    - field: field_common                 # The list type by default. Separated by commas.
    69      range: 1-10, 20-25, 27, 29, 30      # 1,2,3...,10,20,21,22...,25,27,29.30
    70      prefix: int_                        # Prefix
    71      postfix: "\t"                       # Postfix
    72      divider: ","                        # Divider between the fields, only works for text output format.
    73  
    74    - field: field_step                   # Interval steps can be specified.
    75      range: 1-10:2, 1-2:0.1,9-1:-1       # 1,3,5,7,9,1, 1.1,1.2...,2,9,8,7,...,1
    76      postfix: "\t"
    77  
    78    - field: field_random                 # Use R to specify randomly. Set either R or a specified step.
    79      range: 1-10:R                       # 1,5,8...
    80      postfix: "\t"
    81  
    82    - field: field_loop                   # Self-loop field.
    83      range: a-z                          # a_b_c | d_e_f | g_h_i
    84      loop: 3                             # Loop three times.
    85      loopfix: _                          # The connector for each loop.
    86      postfix: "\t"
    87  
    88    - field: field_repeat                 # Use {} to define repeated elements.
    89      range: u-1{3},[u2,u3]{2},[1-3]{3}   # u-1,u-1,u-1,u2,u2,u3,u3,1,1,1,2,2,2,3,3,3
    90      postfix: "\t"
    91  
    92    - field: field_format                 # Output as formatted strings.
    93      range: 1-10                         # passwd 1,passwd 2,passwd 3 ... passwd10。
    94      format: "passwd%02d"
    95      postfix: "\t"
    96  
    97    - field: field_length                 # Fixed length field.
    98      range: 1-99                         # 01\t,02\t,03\t..., 99\t
    99      length: 3                           # the length in Byte including prefix and postfix.
   100      leftpad: 0                          # Using 0 to pad.
   101      postfix: "\t"
   102  
   103    - field: field_text                   # Read a list from a file and set it as random.
   104      range: users.txt:R                  # Using the lines of users.txt as range and set it as random.
   105      postfix: "\t"
   106  
   107    - field: field_yaml                   # use another yaml file's data.
   108      range: 01_range.yaml{3}             # related path.
   109      postfix: "\t"
   110  
   111    - field: field_use_config             # Other definition file can be referred.
   112      config: number.yaml                 # Refer to the definition in number.yaml of the current directory.
   113      postfix: "\t"
   114  
   115    - field: field_use_ranges             # Other definition file can be referred, in which more than one ranges are defined.
   116      from: zentao.number.v1.yaml         # Refer to the ranges in yaml/zentao/number/v1.yaml.
   117      use: medium                         # use medium range.
   118      postfix: "\t"
   119  
   120    - field: field_use_instance           # Refer to other definition file which defines multiple instances.
   121      from: ip.v1.yaml                    # Refer to yaml/ip/v1.yaml.
   122      use: privateB,privateC              # Use the two instances of privateC and privateB defined in this file.
   123      postfix: "\t"
   124  
   125    - field: field_use_excel              # Read the data from the data source of excel.
   126      from: city.v1.city                  # Read the sheet named 'china' in data/address/cn.v1.xlsx.
   127      select: name                        # Query the field city.
   128      where: code = 532                   # Query condition.
   129      rand: true                          # Random for query
   130      postfix: "\t"
   131  
   132    - field: field_with_children          # nested fields.
   133      fields:
   134        - field: child1
   135          range: a-z
   136          prefix: part1_
   137          postfix: '|'
   138  
   139        - field:  child2
   140          range: A-Z
   141          prefix: part2_
   142          postfix: '|'
   143  
   144        - field: child_with_child
   145          prefix: part3_
   146          postfix:
   147          fields:
   148            - field: field_grandson
   149              prefix: int_
   150              range: 10-20
   151              postfix: