Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: command dependence use spf13/cobra instead #234

Merged
merged 8 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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