Skip to content

Commit

Permalink
fix(typo): fix image typo
Browse files Browse the repository at this point in the history
fix image typo

Signed-off-by: ysicing <i@ysicing.me>
  • Loading branch information
ysicing committed Oct 10, 2022
1 parent 1f32db2 commit d75487f
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ jobs:
curl -F package=@$filename https://${FURY_TOKEN}@push.fury.io/ysicing/
curl -F package=@$filename https://${FURY_TOKEN}@push.fury.io/ysicing/
done
- run: ./gen.sh
45 changes: 40 additions & 5 deletions cloud/qcloud/qcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"
"time"

"github.com/ergoapi/util/color"
"github.com/ergoapi/util/output"
"github.com/gosuri/uitable"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -259,19 +260,53 @@ func (c *Client) Scan(id string) error {
return nil
}

func (c *Client) ImageList() error {
func (c *Client) imageList() ([]*cvm.Image, error) {
request := cvm.NewDescribeImagesRequest()
response, err := c.cvmCliet.DescribeImages(request)
request.Offset = common.Uint64Ptr(0)
request.Limit = common.Uint64Ptr(100)
imageList := make([]*cvm.Image, 0)
totalCount := uint64(100)
for *request.Offset < totalCount {
response, err := c.cvmCliet.DescribeImages(request)
if err != nil {
return nil, err
}
if response.Response.ImageSet != nil && len(response.Response.ImageSet) > 0 {
imageList = append(imageList, response.Response.ImageSet...)
}
totalCount = uint64(*response.Response.TotalCount)
request.Offset = common.Uint64Ptr(*request.Offset + uint64(len(response.Response.ImageSet)))
}
return imageList, nil
}

func (c *Client) ImageList(notPublic bool) error {
images, err := c.imageList()
if err != nil {
if _, ok := err.(*errors.TencentCloudSDKError); ok {
return fmt.Errorf("tencent api error has returned: %v", err)
}
return err
}
table := uitable.New()
table.AddRow("创建时间", "Name", "ID", "来源", "OS", "类型", "类型", "状态", "描述")
for _, i := range response.Response.ImageSet {
table.AddRow(i.CreatedTime, i.ImageName, i.ImageId, i.ImageSource, i.OsName, i.ImageType, i.ImageState, i.ImageDescription)
table.AddRow("Name", "ID", "OS", "类型", "状态", "描述")
imageType := ""
imageState := color.SGreen("正常")
for _, i := range images {
if *i.ImageState != "NORMAL" {
imageState = *i.ImageState
}
if *i.ImageType == "PUBLIC_IMAGE" {
if notPublic {
continue
}
imageType = "官方"
} else if *i.ImageType == "PRIVATE_IMAGE" {
imageType = "自定义镜像"
} else {
imageType = "共享镜像"
}
table.AddRow(*i.ImageName, *i.ImageId, *i.OsName, imageType, imageState, *i.ImageDescription)
}
return output.EncodeTable(os.Stdout, table)
}
4 changes: 3 additions & 1 deletion cmd/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@ func cmdImage() *cobra.Command {
}

func cmdImageList() *cobra.Command {
var notPublic bool
c := &cobra.Command{
Use: "list",
Aliases: []string{"ls", "show"},
Short: "列出腾讯云镜像",
RunE: func(c *cobra.Command, args []string) error {
client := qcloud.NewClient()
return client.ImageList()
return client.ImageList(notPublic)
},
}
c.Flags().BoolVar(&notPublic, "skip-public", true, "忽略官方镜像")
return c
}
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewRootCmd() *cobra.Command {
SilenceUsage: true,
SilenceErrors: true,
Short: "腾讯云虚拟机管理工具",
Version: "0.0.3",
Version: "0.0.4",
PersistentPreRunE: func(cobraCmd *cobra.Command, args []string) error {
if globalFlags.Debug {
logrus.SetLevel(logrus.DebugLevel)
Expand Down
57 changes: 57 additions & 0 deletions gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

version=$(cat version.txt)
macosamd64sha=$(cat dist/checksums.txt | grep spot_darwin_amd64 | awk '{print $1}')
macosarm64sha=$(cat dist/checksums.txt | grep spot_darwin_arm64| awk '{print $1}')
linuxamd64sha=$(cat dist/checksums.txt | grep spot_linux_amd64 | awk '{print $1}')
linuxarm64sha=$(cat dist/checksums.txt | grep spot_linux_arm64 | awk '{print $1}')

cat > spotvm.rb <<EOF
class Spotvm < Formula
desc "spot vm tool"
homepage "https://github.com/ysicing/spot"
version "${version}"
if OS.mac?
if Hardware::CPU.arm?
url "https://github.com/ysicing/spot/releases/download/v#{version}/spot_darwin_arm64"
sha256 "${macosarm64sha}"
else
url "https://github.com/ysicing/spot/releases/download/v#{version}/spot_darwin_amd64"
sha256 "${macosamd64sha}"
end
elsif OS.linux?
if Hardware::CPU.intel?
url "https://github.com/ysicing/spot/releases/download/v#{version}/spot_linux_amd64"
sha256 "${linuxamd64sha}"
end
if Hardware::CPU.arm? && Hardware::CPU.is_64_bit?
url "https://github.com/ysicing/spot/releases/download/v#{version}/spot_linux_arm64"
sha256 "${linuxarm64sha}"
end
end
def install
if OS.mac?
if Hardware::CPU.intel?
bin.install "spot_darwin_amd64" => "spotvm"
else
bin.install "spot_darwin_arm64" => "spotvm"
end
elsif OS.linux?
if Hardware::CPU.intel?
bin.install "spot_linux_amd64" => "spotvm"
else
bin.install "spot_linux_arm64" => "spotvm"
end
end
end
test do
assert_match "spotvm vervion v#{version}", shell_output("#{bin}/spotvm -v")
end
end
EOF

cat spotvm.rb
7 changes: 0 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -375,17 +375,10 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/subosito/gotenv v1.4.1 h1:jyEFiXpy21Wm81FBN71l9VoMMV8H8jG+qIK3GCpY6Qs=
github.com/subosito/gotenv v1.4.1/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.498/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.509 h1:xj6NIYbBgeYc9JeHM6YGMJZ3jQkaHsiy9sK4tlrz9wg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.509/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.510 h1:A+gFypbF9m8FtijWByiNcLNO6cwbXsR1lKTYhd7G3Qw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.510/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.498 h1:2lr95hu7AqOuKzEwa+Yij4KgMPkBkqxzk2h6IDOwgLQ=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.498/go.mod h1:sPNzr5h1ZOsO96dk2G80E1D0CUrSxlBtl7iBfwn2XIw=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.510 h1:Nuti3ddj4GB4igyXlzLqcRrvHVazsEU9J+3YpuRh1r0=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.510/go.mod h1:TknQ0KSs8BYwdhOMxsJaAGbuwvRcu5dZ3uA731iAqTY=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.498 h1:85gCxsNf/v+wX35Vb93sUi6uMlcTPLH/JmQ3Mi6Itgs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.498/go.mod h1:5tdfeI6wXEKwD5aVBCQu1vPtSgkLO+Qnqbjiy7zfRfs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.510 h1:/+kHHf8caxdhODIaSVrOy1DEjlc06fpqiloDUMu9Jgo=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cwp v1.0.510/go.mod h1:Vh1E+dvYcmN/hc29drGrrHbF2qCI5wS4VNSW0+eWYc0=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
Expand Down
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.4

0 comments on commit d75487f

Please sign in to comment.