From 3b46daf1c82b9c3cf053c6b2478d8efc9976698e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sun, 22 May 2022 20:45:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81export=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- export.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 export.go diff --git a/export.go b/export.go new file mode 100644 index 0000000..9a33643 --- /dev/null +++ b/export.go @@ -0,0 +1,53 @@ +// Package command ... +// +// Description : command ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2022-05-22 20:34 +package command + +import ( + "fmt" + + "git.zhangdeman.cn/zhangdeman/command/define" +) + +// Export 导入环境变量 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:35 2022/5/22 +func Export() *export { + return &export{} +} + +// export 命令,导入环境变量 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:34 2022/5/22 +type export struct { +} + +// Set 设置环境变量 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:37 2022/5/22 +func (e *export) Set(name string, value string) *define.Result { + return Execute("", "export", []string{fmt.Sprintf("%s=%s", name, value)}) +} + +// BatchSet 批量设置环境变量 +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 20:44 2022/5/22 +func (e *export) BatchSet(data map[string]string) map[string]*define.Result { + result := make(map[string]*define.Result) + for name, value := range data { + result[name] = e.Set(name, value) + } + return result +}