golang notes(12)---use cobra+viper to replace qt

本文介绍了如何用Cobra和Viper库替换基于qt的GUI,以专注于问题解决。通过Cobra创建命令行界面,Viper管理配置文件。例如,使用'ngapp nrrg conf freqband'命令获取当前设置,'ngapp nrrg conf freqband --opBand=n78'进行配置。代码示例展示了子命令的组织方式和Viper的绑定结构。Go语言在正确利用工具后,比Python更优雅且效率更高。
摘要由CSDN通过智能技术生成

In order to focus on problem-solving, I’ve decided to use Cobra+Viper to replace existing thereceipe/qt GUI.

Cobra: https://github.com/spf13/cobra
Viper: https://github.com/spf13/viper

For example:

  • Use cmd ‘ngapp nrrg conf freqband -h’ to get help
D:\dev\go\src\github.com\zhenggao2\ngapp>ngapp nrrg conf freqband -h
nrrg conf freqband can be used to get/set frequency-band related network configurations.

Usage:
  ngapp nrrg conf freqband [flags]

Flags:
      --opBand string   Operating band (default "n41")
  -h, --help            help for freqband

Global Flags:
  -c, --config string   config file (default is $HOME/.ngapp.yaml)
  • Use cmd ‘ngapp nrrg conf freqband’ to get current settings:
D:\dev\go\src\github.com\zhenggao2\ngapp>ngapp nrrg conf freqband
Flag           Type      Current Value    Modifiable
opBand         string    n41              true
_duplexMode    string    TDD              false
_maxDlFreq     int       2690             false
_freqRange     string    FR1              false
  • Use cmd ‘ngapp nrrg conf freqband --opBand=n78’ to configure modifiable flag opBand:
D:\dev\go\src\github.com\zhenggao2\ngapp>ngapp nrrg conf freqband --opBand=n78
nrgrid.FreqBandInfo: {
   3300 MHz-3800 MHz 3300 MHz-3800 MHz TDD 3800}
Available SSB scs: 30KHz
RMSI scs(subcarrierSpacingCommon of MIB) range: 15KHz,30KHz
carrier scs(subcarrierSpacing of SCS-SpecificCarrier) range: 15KHz,30KHz,60KHz
nrgrid.RachInfo: {
   B4 2 [1] [9] 0 1 1 12}
PRACH scs(msg1-SubcarrierSpacing of RACH-ConfigCommon) range: 15KHz,30KHz
Flag           Type      Current Value    Modifiable
opBand         string    n78              true
_duplexMode    string    TDD              false
_maxDlFreq     int       3800             false
_freqRange     string    FR1              false

Now I will introduce the framework:

  1. Former GUI settings are orgnized into separate sub-command:
// nrrgCmd.init
func init() {
   
	nrrgConfCmd.AddCommand(confFreqBandCmd)
	nrrgConfCmd.AddCommand(confSsbGridCmd)
	nrrgConfCmd.AddCommand(confSsbBurstCmd)
	nrrgConfCmd.AddCommand(confMibCmd)
	nrrgConfCmd.AddCommand(confCarrierGridCmd)
	nrrgConfCmd.AddCommand(confCommonSettingCmd)
	nrrgConfCmd.AddCommand(confCss0Cmd)
	nrrgConfCmd.AddCommand(confCoreset1Cmd)
	nrrgConfCmd.AddCommand(confUssCmd)
	nrrgConfCmd.AddCommand(confDci10Cmd)
	nrrgConfCmd.AddCommand(confDci11Cmd)
	nrrgConfCmd.AddCommand(confMsg3Cmd)
	nrrgConfCmd.AddCommand(confDci01Cmd)
	nrrgConfCmd.AddCommand(confBwpCmd)
	nrrgConfCmd.AddCommand(confRachCmd)
	nrrgConfCmd.AddCommand(confDmrsCommonCmd)
	nrrgConfCmd.AddCommand(confDmrsPdschCmd)
	nrrgConfCmd.AddCommand(confPtrsPdschCmd)
	nrrgConfCmd.AddCommand(confDmrsPuschCmd)
	nrrgConfCmd.AddCommand(confPtrsPuschCmd)
	nrrgConfCmd.AddCommand
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值