You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/12/04 09:09:27 UTC

[GitHub] [apisix] tokers commented on a change in pull request #2929: chore: refactor ops in command line

tokers commented on a change in pull request #2929:
URL: https://github.com/apache/apisix/pull/2929#discussion_r535945032



##########
File path: apisix/cli/ops.lua
##########
@@ -0,0 +1,411 @@
+--
+-- 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.
+--
+local ver = require("apisix.core.version")
+local etcd = require("apisix.cli.etcd")
+local util = require("apisix.cli.util")
+local file = require("apisix.cli.file")
+local ngx_tpl = require("apisix.cli.ngx_tpl")
+local template = require("resty.template")
+
+local stderr = io.stderr
+local ipairs = ipairs
+local pairs = pairs
+local print = print
+local type = type
+local tostring = tostring
+local tonumber = tonumber
+local io_open = io.open
+local popen = io.popen
+local execute = os.execute
+local table_insert = table.insert
+local getenv = os.getenv
+local max = math.max
+local floor = math.floor
+local str_find = string.find
+local str_sub = string.sub
+
+local _M = {}
+
+
+local function help()
+    print([[
+Usage: apisix [action] <argument>
+
+help:       show this message, then exit
+init:       initialize the local nginx.conf
+init_etcd:  initialize the data of etcd
+start:      start the apisix server
+stop:       stop the apisix server
+restart:    restart the apisix server
+reload:     reload the apisix server
+version:    print the version of apisix
+]])
+end
+
+
+local function check_version(cur_ver_s, need_ver_s)
+    local cur_vers = util.split(cur_ver_s, [[.]])
+    local need_vers = util.split(need_ver_s, [[.]])
+    local len = max(#cur_vers, #need_vers)
+
+    for i = 1, len do
+        local cur_ver = tonumber(cur_vers[i]) or 0
+        local need_ver = tonumber(need_vers[i]) or 0
+        if cur_ver > need_ver then
+            return true
+        end
+
+        if cur_ver < need_ver then
+            return false
+        end
+    end
+
+    return true
+end
+
+
+local function get_openresty_version()
+    local str = "nginx version: openresty/"
+    local ret = util.execute_cmd("openresty -v 2>&1")
+    local pos = str_find(ret, str)

Review comment:
       @spacewander Fixed.

##########
File path: apisix/cli/ops.lua
##########
@@ -0,0 +1,411 @@
+--
+-- 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.
+--
+local ver = require("apisix.core.version")
+local etcd = require("apisix.cli.etcd")
+local util = require("apisix.cli.util")
+local file = require("apisix.cli.file")
+local ngx_tpl = require("apisix.cli.ngx_tpl")
+local template = require("resty.template")
+
+local stderr = io.stderr
+local ipairs = ipairs
+local pairs = pairs
+local print = print
+local type = type
+local tostring = tostring
+local tonumber = tonumber
+local io_open = io.open
+local popen = io.popen
+local execute = os.execute
+local table_insert = table.insert
+local getenv = os.getenv
+local max = math.max
+local floor = math.floor
+local str_find = string.find
+local str_sub = string.sub
+
+local _M = {}
+
+
+local function help()
+    print([[
+Usage: apisix [action] <argument>
+
+help:       show this message, then exit
+init:       initialize the local nginx.conf
+init_etcd:  initialize the data of etcd
+start:      start the apisix server
+stop:       stop the apisix server
+restart:    restart the apisix server
+reload:     reload the apisix server
+version:    print the version of apisix
+]])
+end
+
+
+local function check_version(cur_ver_s, need_ver_s)
+    local cur_vers = util.split(cur_ver_s, [[.]])
+    local need_vers = util.split(need_ver_s, [[.]])
+    local len = max(#cur_vers, #need_vers)
+
+    for i = 1, len do
+        local cur_ver = tonumber(cur_vers[i]) or 0
+        local need_ver = tonumber(need_vers[i]) or 0
+        if cur_ver > need_ver then
+            return true
+        end
+
+        if cur_ver < need_ver then
+            return false
+        end
+    end
+
+    return true
+end
+
+
+local function get_openresty_version()
+    local str = "nginx version: openresty/"
+    local ret = util.execute_cmd("openresty -v 2>&1")
+    local pos = str_find(ret, str)
+    if pos then
+        return str_sub(ret, pos + #str)
+    end
+
+    str = "nginx version: nginx/"
+    pos = str_find(ret, str)

Review comment:
       @spacewander Fixed.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org