Skip to content

Commit

Permalink
Merge pull request apache#234 from MasterKenway/refactor/cli-cobra
Browse files Browse the repository at this point in the history
refactor: command dependence use spf13/cobra instead
Former-commit-id: ac2c232
  • Loading branch information
AlexStocks committed Aug 7, 2021
2 parents d780c10 + e65c03a commit c407377
Show file tree
Hide file tree
Showing 18 changed files with 306 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pkg/registry/zookeeper-4unittest/contrib/fatjar

coverage.txt

/vendor/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ script:
- go fmt ./... && [[ -z `git status -s` ]]
- sh before_validate_license.sh
- chmod u+x /tmp/tools/license/license-header-checker
- /tmp/tools/license/license-header-checker -v -a -r -i vendor -i .github/actions /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
- /tmp/tools/license/license-header-checker -v -a -r -i vendor,.github/actions /tmp/tools/license/license.txt . go && [[ -z `git status -s` ]]
# unit-test
- echo 'start unit-test'
- chmod u+x before_ut.sh && ./before_ut.sh
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ ifeq (windows,$(os))
targetName = dubbo-go-pixiu.exe
endif
exe := $(mainPath)$(targetName)
gobuild:
build:
cd $(mainPath) && go build -o $(currentPath)/$(targetName) *.go

run: build
./dubbo-go-pixiu start -a $(api-config-path) -c $(config-path)
./dubbo-go-pixiu gateway start -a $(api-config-path) -c $(config-path)

license-check-util:
go install github.com/lsm-dev/license-header-checker/cmd/license-header-checker@latest
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ go build -o pixiu cmd/pixiu/*.go
#### 2.3 Execute the binary file in the project root directory

```
./pixiu start
./pixiu gateway start
```

### 3. Try a request
Expand Down
2 changes: 1 addition & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ go build -o pixiu cmd/pixiu/*.go
#### 2.3 启动pixiu,在根目录执行

```
./pixiu start
./pixiu gateway start
```

### 3. 发起请求
Expand Down
139 changes: 0 additions & 139 deletions cmd/pixiu/control.go

This file was deleted.

82 changes: 82 additions & 0 deletions cmd/pixiu/gateway.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/

package main

import (
"os"
)

import (
"github.com/spf13/cobra"
)

import (
"github.com/apache/dubbo-go-pixiu/pkg/common/constant"
"github.com/apache/dubbo-go-pixiu/pkg/logger"
"github.com/apache/dubbo-go-pixiu/pkg/pixiu"
)

var (
gatewayCmd = &cobra.Command{
Use: "gateway",
Short: "Run dubbo go pixiu in gateway mode",
}

startGatewayCmd = &cobra.Command{
Use: "start",
Short: "Start gateway",
Version: Version,
PreRun: func(cmd *cobra.Command, args []string) {
initDefaultValue()
},
Run: func(cmd *cobra.Command, args []string) {
err := initLog()
if err != nil {
logger.Warnf("[startGatewayCmd] failed to init logger, %s", err.Error())
}

bootstrap, meta, err := initApiConfig()
if err != nil {
if meta {
logger.Warnf("[startGatewayCmd] failed to get api meta config, %s", err.Error())
} else {
logger.Errorf("[startGatewayCmd] failed to get api meta config, %s", err.Error())
}
}

err = initLimitCpus()
if err != nil {
logger.Errorf("[startCmd] failed to get limit cpu number, %s", err.Error())
}

pixiu.Start(bootstrap)
},
}
)

// init Init startCmd
func init() {
startGatewayCmd.PersistentFlags().StringVarP(&configPath, constant.ConfigPathKey, "c", os.Getenv(constant.EnvDubbogoPixiuConfig), "Load configuration from `FILE`")
startGatewayCmd.PersistentFlags().StringVarP(&apiConfigPath, constant.ApiConfigPathKey, "a", os.Getenv(constant.EnvDubbogoPixiuApiConfig), "Load api configuration from `FILE`")
startGatewayCmd.PersistentFlags().StringVarP(&logConfigPath, constant.LogConfigPathKey, "g", os.Getenv(constant.EnvDubbogoPixiuLogConfig), "Load log configuration from `FILE`")
startGatewayCmd.PersistentFlags().StringVarP(&logLevel, constant.LogLevelKey, "l", os.Getenv(constant.EnvDubbogoPixiuLogLevel), "dubbogo pixiu log level, trace|debug|info|warning|error|critical")
startGatewayCmd.PersistentFlags().StringVarP(&limitCpus, constant.LimitCpusKey, "m", os.Getenv(constant.EnvDubbogoPixiuLimitCpus), "dubbogo pixiu schedule threads count")
startGatewayCmd.PersistentFlags().StringVarP(&logFormat, constant.LogFormatKey, "f", os.Getenv(constant.EnvDubbogoPixiuLogFormat), "dubbogo pixiu log format, currently useless")

gatewayCmd.AddCommand(startGatewayCmd)
}
Loading

0 comments on commit c407377

Please sign in to comment.