Skip to content

Commit

Permalink
edit: improve stability when files are still being downloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
just-hms committed Oct 3, 2024
1 parent 273a1b3 commit c0a0e69
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 32 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
50 changes: 25 additions & 25 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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 ./...
6 changes: 4 additions & 2 deletions cmd/mv.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
23 changes: 18 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
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")
}
21 changes: 21 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 3 additions & 0 deletions internal/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package internal

var Version = "dev"

0 comments on commit c0a0e69

Please sign in to comment.