eryajfctl

command module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 3 Imported by: 0

README

eryajfctl

Auth Eryajf HitCount GitHub license GitHub Stars Eryajf Blog Eryajf WeChat Eryajf Awesome Stars

🌉 基于Cobra库快速开发类似kubectl一样的命令行工具框架 🌉


运维也可以如此优雅!快用这个框架打造一个专属于你的工具箱吧!

通过这个框架,你可以快速上手,直接构建你想要的运维工具,而不必再考虑配置,框架设计等内容。

如何使用

先拷贝配置文件:

cp config.example.yml config.yml

执行如下指令,运行示例参数:

$ go run main.go ex getconfig -w "hello, This is eryajfctl"
通过配置文件获取到的用户名: eryajf
通过配置文件获取到的密码: 123456
通过命令行获取到的内容是: hello, This is eryajfctl

其中ex为一级参数,getconfig为二级参数,大多数场景下,分两个层级就够用了,你可以把一级参数当做归类,比如 jenkins, gitlab,二级参数当做功能参数,再往后的参数则是该二级参数所需要的运行时参数。

也可以编译成二进制,然后通过如下方式查看帮助信息:

# 编译
$ make build

#运行测试
$ ./eryajfctl ex getconfig -h
通过命令行获取配置信息

Usage:
  eryajfctl ex getconfig [flags]

Flags:
  -h, --help          help for getconfig
  -w, --word string   测试参数 (default "你好,这是测试")

开始开发

你可以直接参考ex参数的流程,开发新的参数,从而满足实际使用需求。

如果你的配置文件中有敏感数据,可以考虑结合go-bindata来使用,通过执行:

go-bindata -o=./public/bindata_config.go -pkg=public config.yml

然后更改 public/config.go 中的配置信息读取方式,接着进入开发即可。

如果后续本地的config.yml配置有更新,则再次执行上边的命令,将配置文件注入到 bindata_config.go 即可。

这样做的一个好处是,你的二进制放到服务器等地运行的时候,既不需要添加config.yml文件,也能防止文件中的敏感信息暴漏出去。

生成文档

执行如下命令,会自动生成该工具的文档,且生成子命令的文档。

$ ./eryajfctl --md-docs

在这里你可以看到所有的文档:点我查看

感谢开源

此框架建立在如下几个优秀的开源项目之上:

其他参考

如果你想熟悉了解此框架的详细用法,还可以参考我的如下两篇文章:

项目源码

可选择你熟悉的平台浏览源码:

服务商 地址
CNB https://cnb.cool/eryajf/eryajfctl
GitHub https://github.com/eryajf/eryajfctl

Documentation

Overview

Copyright © 2021 eryajf

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
api
ex
public

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL