Skip to content

Commit

Permalink
Merge pull request #46 from jkawamoto/hotfix/v0.7.1
Browse files Browse the repository at this point in the history
Hotfix/v0.7.1
  • Loading branch information
jkawamoto authored Apr 8, 2023
2 parents a9f96c9 + f36d8e1 commit bdc4a6a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.7.0
current_version = 0.7.1
commit = True

[bumpversion:file:README.md]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HOMEBREW_TAP_GITHUB_TOKEN: ${{ secrets.HOMEBREW_TAP_GITHUB_TOKEN }}
9 changes: 9 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,12 @@ jobs:
uses: golangci/golangci-lint-action@v3
with:
version: latest
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: ">=1.20"
- name: Run tests
run: go test -race -v ./...
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ brews:
tap:
owner: jkawamoto
name: homebrew-pixeldrain
token: "{{ .Env.HOMEBREW_TAP_GITHUB_TOKEN }}"
nfpms:
- package_name: pixeldrain
homepage: https://jkawamoto.github.io/go-pixeldrain/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Go application](https://github.com/jkawamoto/go-pixeldrain/actions/workflows/test.yaml/badge.svg)](https://github.com/jkawamoto/go-pixeldrain/actions/workflows/test.yaml)
[![Go Reference](https://pkg.go.dev/badge/github.com/jkawamoto/go-pixeldrain.svg)](https://pkg.go.dev/github.com/jkawamoto/go-pixeldrain)
[![codecov](https://codecov.io/gh/jkawamoto/go-pixeldrain/branch/master/graph/badge.svg?token=ppX3MVIqWA)](https://codecov.io/gh/jkawamoto/go-pixeldrain)
[![Release](https://img.shields.io/badge/release-0.7.0-brightgreen.svg)](https://github.com/jkawamoto/go-pixeldrain/releases/tag/v0.7.0)
[![Release](https://img.shields.io/badge/release-0.7.1-brightgreen.svg)](https://github.com/jkawamoto/go-pixeldrain/releases/tag/v0.7.1)


## Usage
Expand Down
29 changes: 27 additions & 2 deletions cmd/pd/command/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package command

import (
"encoding/csv"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -108,8 +109,11 @@ func CmdUpload(c *cli.Context) error {

var ids []string
for i := 0; i != c.NArg(); i++ {
path, name, _ := strings.Cut(c.Args().Get(i), ":")

path, name, err := parseArgument(c.Args().Get(i))
if err != nil {
return cli.Exit(
fmt.Errorf("failed to parse argument %q: %w", c.Args().Get(i), err), status.InvalidArgument)
}
id, err := upload(c, path, name, recipients)
if err != nil {
return cli.Exit(fmt.Errorf("failed to upload %v: %w", path, err), status.APIError)
Expand Down Expand Up @@ -183,3 +187,24 @@ func parseRecipientFile(name string) (_ []age.Recipient, err error) {

return age.ParseRecipients(f)
}

func parseArgument(arg string) (path string, name string, _ error) {
volume := filepath.VolumeName(arg)
arg = strings.TrimPrefix(arg, volume)

r := csv.NewReader(strings.NewReader(arg))
r.Comma = ':'
res, err := r.Read()
if err != nil {
return "", "", err
}

switch len(res) {
case 0:
return "", "", nil
case 1:
return volume + res[0], "", nil
default:
return volume + res[0], res[1], nil
}
}
42 changes: 42 additions & 0 deletions cmd/pd/command/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,3 +473,45 @@ func TestUpload(t *testing.T) {
})
}
}

func Test_parseArgument(t *testing.T) {
tests := []struct {
arg string
wantPath string
wantName string
}{
{
arg: "path_only",
wantPath: "path_only",
},
{
arg: "simple:case",
wantPath: "simple",
wantName: "case",
},
{
arg: "\"quoted path only\"",
wantPath: "quoted path only",
wantName: "",
},
{
arg: "\"quoted path only\":\"quoted name\"",
wantPath: "quoted path only",
wantName: "quoted name",
},
}
for _, tt := range tests {
t.Run(tt.arg, func(t *testing.T) {
gotPath, gotName, err := parseArgument(tt.arg)
if err != nil {
t.Fatal(err)
}
if gotPath != tt.wantPath {
t.Errorf("parseArgument() gotPath = %v, want %v", gotPath, tt.wantPath)
}
if gotName != tt.wantName {
t.Errorf("parseArgument() gotName = %v, want %v", gotName, tt.wantName)
}
})
}
}
53 changes: 53 additions & 0 deletions cmd/pd/command/upload_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// upload_windows_test.go
//
// Copyright (c) 2018-2023 Junpei Kawamoto
//
// This software is released under the MIT License.
//
// http://opensource.org/licenses/mit-license.php

package command

import "testing"

func Test_parseArgument_windows(t *testing.T) {
tests := []struct {
arg string
wantPath string
wantName string
}{
{
arg: "\"C:\\windows\\path_only\"",
wantPath: "C:\\windows\\path_only",
},
{
arg: "\"C:\\windows path\":\"quoted name\"",
wantPath: "C:\\windows path",
wantName: "quoted name",
},
{
arg: "C:\\windows\\unquoted_path",
wantPath: "C:\\windows\\unquoted_path",
},
{
arg: "C:\\windows unquoted_path:\"quoted name\"",
wantPath: "C:\\windows unquoted_path",
wantName: "quoted name",
},
}
for _, tt := range tests {
t.Run(tt.arg, func(t *testing.T) {
gotPath, gotName, err := parseArgument(tt.arg)
if err != nil {
t.Fatal(err)
}
if gotPath != tt.wantPath {
t.Errorf("parseArgument() gotPath = %v, want %v", gotPath, tt.wantPath)
}
if gotName != tt.wantName {
t.Errorf("parseArgument() gotName = %v, want %v", gotName, tt.wantName)
}
})
}
}
2 changes: 1 addition & 1 deletion cmd/pd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
// Name defines the basename of this program.
Name = "pd"
// Version defines current version number.
Version = "0.7.0"
Version = "0.7.1"
)

// commandNotFound shows error message and exit when a given command is not found.
Expand Down

0 comments on commit bdc4a6a

Please sign in to comment.