Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
57 changes: 57 additions & 0 deletions .github/workflows/go-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: go-build

on: [push, pull_request]

env:
BINARY_PREFIX: "cloudpan189-go_"
BINARY_SUFFIX: ""
PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request."
LD_FLAGS: "-w -s"

jobs:
build:
name: Build binary CI
runs-on: ubuntu-latest
strategy:
matrix:
# build and publish in parallel: linux/386, linux/amd64, windows/386, windows/amd64, darwin/amd64, darwin/arm64
goos: [linux, windows, darwin]
goarch: ["386", amd64, arm, arm64]
exclude:
- goos: darwin
goarch: arm
- goos: darwin
goarch: "386"
- goos: windows
goarch: arm64
fail-fast: true
steps:
- uses: actions/checkout@v4
- name: Setup Go environment
uses: actions/setup-go@v5
with:
go-version: 1.22
- name: Cache downloaded module
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('**/go.sum') }}
- name: Build binary file
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
IS_PR: ${{ !!github.head_ref }}
run: |
if [ $GOOS = "windows" ]; then export BINARY_SUFFIX="$BINARY_SUFFIX.exe"; fi
if $IS_PR ; then echo $PR_PROMPT; fi
export BINARY_NAME="$BINARY_PREFIX$GOOS_$GOARCH$BINARY_SUFFIX"
export CGO_ENABLED=0
go build -o "output/$BINARY_NAME" -trimpath -ldflags "$LD_FLAGS" .
- name: Upload artifact
uses: actions/upload-artifact@v4
if: ${{ !github.head_ref }}
with:
name: ${{ matrix.goos }}_${{ matrix.goarch }}
path: output/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/tickstep/cloudpan189-go

go 1.20
go 1.22

require (
github.com/GeertJohan/go.incremental v1.0.0
Expand Down
39 changes: 30 additions & 9 deletions internal/command/ls_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand All @@ -14,7 +14,11 @@
package command

import (
"encoding/json"
"fmt"
"os"
"strconv"

"github.com/olekukonko/tablewriter"
"github.com/tickstep/cloudpan189-api/cloudpan"
"github.com/tickstep/cloudpan189-go/cmder"
Expand All @@ -23,8 +27,6 @@ import (
"github.com/tickstep/library-go/converter"
"github.com/tickstep/library-go/text"
"github.com/urfave/cli"
"os"
"strconv"
)

type (
Expand Down Expand Up @@ -67,6 +69,9 @@ func CmdLs() cli.Command {

按文件大小降序排序
cloudpan189-go ls -size -desc 我的资源

json 格式输出
cloudpan189-go ls -json 我的资源
`,
Category: "天翼云盘",
Before: cmder.ReloadConfigFunc,
Expand Down Expand Up @@ -99,10 +104,14 @@ func CmdLs() cli.Command {
default:
orderBy = cloudpan.OrderByTime
}
var json_output bool = false
if c.IsSet("json") {
json_output = true
}

RunLs(parseFamilyId(c), c.Args().Get(0), &LsOptions{
Total: c.Bool("l") || c.Parent().Args().Get(0) == "ll",
}, orderBy, orderSort)
}, orderBy, orderSort, json_output)

return nil
},
Expand Down Expand Up @@ -136,15 +145,19 @@ func CmdLs() cli.Command {
Usage: "家庭云ID",
Value: "",
},
cli.BoolFlag{
Name: "json",
Usage: "JSON 格式输出",
},
},
}
}

func RunLs(familyId int64, targetPath string, lsOptions *LsOptions, orderBy cloudpan.OrderBy, orderSort cloudpan.OrderSort) {
func RunLs(familyId int64, targetPath string, lsOptions *LsOptions, orderBy cloudpan.OrderBy, orderSort cloudpan.OrderSort, isJson bool) {
activeUser := config.Config.ActiveUser()
targetPath = activeUser.PathJoin(familyId, targetPath)
if targetPath[len(targetPath) - 1] == '/' {
targetPath = text.Substr(targetPath, 0, len(targetPath) - 1)
if targetPath[len(targetPath)-1] == '/' {
targetPath = text.Substr(targetPath, 0, len(targetPath)-1)
}

targetPathInfo, err := activeUser.PanClient().AppFileInfoByPath(familyId, targetPath)
Expand Down Expand Up @@ -183,10 +196,18 @@ func RunLs(familyId int64, targetPath string, lsOptions *LsOptions, orderBy clou
} else {
fileList = append(fileList, targetPathInfo)
}
renderTable(opLs, lsOptions.Total, targetPath, fileList)
if isJson {
data, err := json.Marshal(fileList)
if err != nil {
fmt.Print("{\"error\":\"", err.Error(), "\"}")
} else {
fmt.Print(string(data))
}
} else {
renderTable(opLs, lsOptions.Total, targetPath, fileList)
}
}


func renderTable(op int, isTotal bool, path string, files cloudpan.AppFileList) {
tb := cmdtable.NewTable(os.Stdout)
var (
Expand Down