From c0a0e69a9e8888f22a54fded49be5f409405ffe3 Mon Sep 17 00:00:00 2001 From: just-hms Date: Thu, 3 Oct 2024 11:41:16 +0200 Subject: [PATCH] edit: improve stability when files are still being downloaded --- .github/workflows/release.yml | 27 +++++++++++++++++++ .github/workflows/test.yml | 50 +++++++++++++++++------------------ cmd/mv.go | 6 +++-- cmd/root.go | 23 ++++++++++++---- cmd/version.go | 21 +++++++++++++++ internal/version.go | 3 +++ 6 files changed, 98 insertions(+), 32 deletions(-) create mode 100644 .github/workflows/release.yml create mode 100644 cmd/version.go create mode 100644 internal/version.go diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..27127bf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,27 @@ +name: release + +on: + release: + types: + - created + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set version + run: + with: + go-version: 1.22 + + - name: Check version + run: go version + + - name: Build executables + run: | + export VERSION=${{ github.ref_name }} + sed -i 's/Version = "dev"/Version = "'"$VERSION"'"/' internal/version.go + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 03f0db3..42236b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,32 +1,32 @@ -name: Go Test +# name: Go Test -on: - push: - branches: - - main +# on: +# push: +# branches: +# - main -jobs: - test: - name: Test on ${{ matrix.os }} - runs-on: ${{ matrix.os }} +# jobs: +# test: +# name: Test on ${{ matrix.os }} +# runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, macos-latest] +# strategy: +# matrix: +# os: [ubuntu-latest, macos-latest] - steps: - - name: Checkout repository - uses: actions/checkout@v4 +# steps: +# - name: Checkout repository +# uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: '1.22' +# - name: Set up Go +# uses: actions/setup-go@v5 +# with: +# go-version: '1.22' - - name: Install dependencies - run: | - go mod tidy - go mod download +# - name: Install dependencies +# run: | +# go mod tidy +# go mod download - - name: Run tests - run: go test ./... +# - name: Run tests +# run: go test ./... diff --git a/cmd/mv.go b/cmd/mv.go index 736ae15..21f4cc0 100644 --- a/cmd/mv.go +++ b/cmd/mv.go @@ -77,9 +77,9 @@ func waitForDownload(logger logx.Logger, downloadPath string) (fs.FileInfo, erro } var mvCmd = &cobra.Command{ - Use: "dow", + Use: "move", Short: "move the last downloaded file in the current (or the specified) folder", - Long: ``, + Hidden: true, SilenceUsage: false, Args: cobra.RangeArgs(0, 1), RunE: func(cmd *cobra.Command, args []string) error { @@ -129,6 +129,8 @@ var mvCmd = &cobra.Command{ } func init() { + rootCmd.AddCommand(mvCmd) + mvCmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "show the name of the moved file") mvCmd.Flags().BoolVarP(&yesFlag, "yes", "y", false, "force dow to move the latest file even if it's old") } diff --git a/cmd/root.go b/cmd/root.go index 9cb3d1d..259ff20 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,17 +1,30 @@ -/* -Copyright © 2024 NAME HERE -*/ package cmd import ( "os" + + "github.com/spf13/cobra" ) +var rootCmd = &cobra.Command{ + Use: "dow", + Short: "move the last downloaded file in the current (or the specified) folder", + Example: "use `dow` or `dow /target/folder` to move the latest file where you want", + RunE: func(cmd *cobra.Command, args []string) error { + return mvCmd.RunE(cmd, args) + }, +} + func Execute() { - err := mvCmd.Execute() + err := rootCmd.Execute() if err != nil { os.Exit(1) } } -func init() {} +func init() { + rootCmd.Root().CompletionOptions.DisableDefaultCmd = true + + rootCmd.Flags().BoolVarP(&verboseFlag, "verbose", "v", false, "show the name of the moved file") + rootCmd.Flags().BoolVarP(&yesFlag, "yes", "y", false, "force dow to move the latest file even if it's old") +} diff --git a/cmd/version.go b/cmd/version.go new file mode 100644 index 0000000..40b6133 --- /dev/null +++ b/cmd/version.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "fmt" + + "github.com/just-hms/dow/internal" + "github.com/spf13/cobra" +) + +// versionCmd represents the version command +var versionCmd = &cobra.Command{ + Use: "version", + Short: "displays the version of dow", + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(internal.Version) + }, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/internal/version.go b/internal/version.go new file mode 100644 index 0000000..72d43df --- /dev/null +++ b/internal/version.go @@ -0,0 +1,3 @@ +package internal + +var Version = "dev"