github.com/KusionStack/kpm@v0.8.4-0.20240326033734-dc72298a30e5/docs/command-reference-zh/11.import.md (about)

     1  # kpm import
     2  
     3  将其它格式的文件转换为 kcl 文件。
     4  
     5  ## 使用
     6  
     7  ```shell
     8  kpm import [options] <file>
     9  ```
    10  
    11  ## 介绍
    12  
    13  `kpm import` 会从指定的文件中读取内容,并将其转换为 kcl 文件。
    14  
    15  ## 选项
    16  
    17  ### --mode, -m
    18  
    19  指定转换模式,默认值为 `auto`,以下是支持的模式:
    20  
    21  - `json`: 将 json 数据转换为 kcl 数据。
    22  - `yaml`: 将 yaml 数据转换为 kcl 数据。
    23  - `gostruct`: 将 go 结构体转换为 kcl schema。
    24  - `jsonschema`: 将 json schema 转换为 kcl schema。
    25  - `terraformschema`: 将 terraform provider schema 转换为 kcl schema。关于如何获取 terraform provider schema 文件,请参考 [terraform schema](https://developer.hashicorp.com/terraform/cli/commands/providers/schema)。
    26  - `auto`: 自动检测文件类型,并使用对应的转换模式。
    27  
    28  ### --output, -o
    29  
    30  指定输出文件名,默认值为 `generated.k`。
    31  
    32  ### --force, -f
    33  
    34  强制覆盖输出文件。
    35  
    36  ### --help, -h
    37  
    38  展示 `kpm import` 命令的帮助信息。
    39  
    40  ## 示例
    41  
    42  使用 `kpm import` 将 yaml 数据转换为 kcl 数据。
    43  
    44  ```
    45  $ cat <<EOF > foo.yaml
    46  kind: Service
    47  name: kcl
    48  EOF
    49  
    50  $ kpm import foo.yaml
    51  
    52  $ cat generated.k
    53  """
    54  This file was generated by the KCL auto-gen tool. DO NOT EDIT.
    55  Editing this file might prove futile when you re-run the KCL auto-gen generate command.
    56  """
    57  
    58  kind = "Service"
    59  name = "kcl"
    60  ```