Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/template #42

Merged
merged 39 commits into from
Dec 2, 2023
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
146470d
chore: Goとライブラリのバージョンをアップデート
xztaityozx Nov 6, 2023
20b467c
refactor: srcディレクトリを掘ってそこにGoのソースコードを置くように
xztaityozx Nov 6, 2023
eda3dca
Revert "refactor: srcディレクトリを掘ってそこにGoのソースコードを置くように"
xztaityozx Nov 6, 2023
4fcd307
chore: asdf向けのファイルも更新
xztaityozx Nov 6, 2023
91913f8
refactor: ライブラリ系をinternal以下に移動した
xztaityozx Nov 6, 2023
051d1a8
refactor: ファイル名を専用のものに切り替えた
xztaityozx Nov 6, 2023
84ffde1
chore: project-layoutsに従って画像をassets以下に置いた
xztaityozx Nov 6, 2023
e5f0c99
refactor: io系パッケージを分離
xztaityozx Nov 6, 2023
81995a6
refactor: SetAutoFlushを廃止してNewWriterで指定するように
xztaityozx Nov 6, 2023
565b0ee
refactor: 不要なコメントを削除
xztaityozx Nov 6, 2023
4f046a0
refactor: option.Option 型を変更するときに大変なので式を変更した
xztaityozx Nov 6, 2023
06a878e
feat: 出力フォーマットを指定できるように
xztaityozx Nov 6, 2023
242ea9a
fix: インターフェースが変わったもののテストは修正してなかったやつをなおした
xztaityozx Nov 6, 2023
28decc8
fix: テストの引数を間違えていました
xztaityozx Nov 6, 2023
4c4d33e
fix: 改行が必要なのでここでreturnしてはいけない
xztaityozx Nov 6, 2023
1d2653d
feat: ローカル開発用のMakefileを用意した
xztaityozx Nov 6, 2023
ca4de06
test: E2Eテストを追加
xztaityozx Nov 11, 2023
a1e3c99
fix: fix typo
xztaityozx Nov 11, 2023
9d18c1b
chore: bashを指定した方がよさそう
xztaityozx Nov 11, 2023
86d700a
chore: なんかテストが落ちない?
xztaityozx Nov 11, 2023
1432e75
refactor: Linux/darwinで動かすテストなのでディレクトリを切った
xztaityozx Dec 1, 2023
f1b8c6e
test: e2eテストを実装した
xztaityozx Dec 1, 2023
0bc4935
chore: 各OSで各シェルのテストを動かす
xztaityozx Dec 1, 2023
ed617f0
refactor: どんなテストで落ちてるのかしらべる
xztaityozx Dec 1, 2023
7de4979
chore: powershell用に調整
xztaityozx Dec 1, 2023
0bd4544
feat: テスト中に1つでも失敗したら全体の終了ステータスを異常終了にしたい
xztaityozx Dec 1, 2023
bcadb0c
test: テストケースをマルチバイトから変更
xztaityozx Dec 1, 2023
01d356d
test: windows側のテストケースも変更する
xztaityozx Dec 1, 2023
358ccd1
feat: pwshでのテストにPesterを使う
xztaityozx Dec 1, 2023
d162604
feat: Get-Contentにエンコーディングを指定することで出力に失敗しないようにする
xztaityozx Dec 1, 2023
8bc546a
test: stdinからではなく -f オプション経由で入力するようにしてみる
xztaityozx Dec 2, 2023
9e59fab
refactor: linterは必須ではない
xztaityozx Dec 2, 2023
bcec652
test: 空白文字列をpowershellで指定するのは難しいのでテストケースを見直した
xztaityozx Dec 2, 2023
1d8e83b
feat: ワークフローを起動する条件を変更する
xztaityozx Dec 2, 2023
a3db6ec
feat: OSにあった拡張子を出力できるようにmakeを変更
xztaityozx Dec 2, 2023
58e1efc
feat: パスを自動で解決できるようにする
xztaityozx Dec 2, 2023
426d5d2
fix: Pester経由で起動するとパスが解決できない
xztaityozx Dec 2, 2023
c0a79cd
test: Test-Pathをつかう
xztaityozx Dec 2, 2023
b534c27
test: windows-latestではテストしない
xztaityozx Dec 2, 2023
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
Prev Previous commit
Next Next commit
refactor: srcディレクトリを掘ってそこにGoのソースコードを置くように
  • Loading branch information
xztaityozx committed Nov 6, 2023
commit 20b467c8b9334bac0ec1d836139d20ab95a0ff39
45 changes: 0 additions & 45 deletions cmd/completion.go

This file was deleted.

2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

import (
"github.com/xztaityozx/sel/cmd"
"github.com/xztaityozx/sel/src/cmd"
)

func main() {
45 changes: 45 additions & 0 deletions src/cmd/completion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"log"
"os"

"github.com/spf13/cobra"
)

var completionCmd = &cobra.Command{
Use: "completion [bash|zsh|fish|powershell]",
Short: "Generate completion script",
DisableFlagsInUseLine: true,
ValidArgs: []string{"bash", "zsh", "fish", "powershell"},
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
err := cmd.Root().GenBashCompletion(os.Stdout)
if err != nil {
log.Fatalln(err)
}
case "zsh":
err := cmd.Root().GenZshCompletion(os.Stdout)
if err != nil {
log.Fatalln(err)
}
case "fish":
err := cmd.Root().GenFishCompletion(os.Stdout, true)
if err != nil {
log.Fatalln(err)
}
case "powershell":
err := cmd.Root().GenPowerShellCompletionWithDesc(os.Stdout)
if err != nil {
log.Fatalln(err)
}
}
},
}

func init() {
rootCmd.AddCommand(completionCmd)
completionCmd.SetUsageTemplate(completionCmd.Use)
}
8 changes: 4 additions & 4 deletions cmd/root.go → src/cmd/root.go
Original file line number Diff line number Diff line change
@@ -8,13 +8,13 @@ import (
"os"
"strings"

"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/xztaityozx/sel/column"
"github.com/xztaityozx/sel/option"
"github.com/xztaityozx/sel/parser"
"github.com/xztaityozx/sel/src/column"
"github.com/xztaityozx/sel/src/option"
"github.com/xztaityozx/sel/src/parser"
)

var Version string = "undefined"
2 changes: 1 addition & 1 deletion column/index.go → src/column/index.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package column
import (
"strconv"

"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"
)

// IndexSelector は単一のindexを指定してカラムを選択するやつ
6 changes: 3 additions & 3 deletions column/index_test.go → src/column/index_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package column
import (
"bytes"
"github.com/stretchr/testify/assert"
"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"
"github.com/xztaityozx/sel/test_util"
"math/rand"
"reflect"
@@ -43,15 +43,15 @@ func TestNewIndexSelectorFromString(t *testing.T) {
}

func TestNewIndexSelector(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
expect := rand.Int()
actual := NewIndexSelector(expect)
assert.Equal(t, expect, actual.index)
}

func TestIndexSelector_Select(t *testing.T) {

rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < 10; i++ {
var cols []string
for k := 0; k < 10; k++ {
14 changes: 7 additions & 7 deletions column/range.go → src/column/range.go
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ package column

import (
"fmt"
"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"
)

// RangeSelector はカラムの範囲選択するやつ
@@ -19,25 +19,25 @@ func NewRangeSelector(start, step, stop int, isInfStop bool) RangeSelector {

func (r RangeSelector) Select(w *Writer, iter iterator.IEnumerable) error {
strings := iter.ToArray()
max := len(strings)
m := len(strings)

start := r.start
if start < 0 {
start = max + start + 1
start = m + start + 1
}

stop := r.stop
if r.isInfStop || stop >= max {
stop = max
if r.isInfStop || stop >= m {
stop = m
}
if stop < 0 {
stop = max + stop + 1
stop = m + stop + 1
}

step := r.step

if start == stop {
if start > max {
if start > m {
return fmt.Errorf("index out of range")
}

4 changes: 2 additions & 2 deletions column/range_test.go → src/column/range_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
)

func TestNewRangeSelector(t *testing.T) {
rand.Seed(time.Now().UnixNano())
rand.New(rand.NewSource(time.Now().UnixNano()))
start := rand.Int()
step := rand.Int()
stop := rand.Int()
@@ -63,7 +63,7 @@ func TestRangeSelector_Select(t *testing.T) {
err := rs.Select(writer, &testEnumerable{a: cols})
assert.Nil(t, writer.Flush())
assert.Nil(t, err)
assert.Equal(t, strings.Join(expect, " "), w.String() , "start: %d, step: %d, stop: %d", v.start, v.step, v.stop)
assert.Equal(t, strings.Join(expect, " "), w.String(), "start: %d, step: %d, stop: %d", v.start, v.step, v.stop)
w.Reset()
}
})
2 changes: 1 addition & 1 deletion column/selector.go → src/column/selector.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package column

import "github.com/xztaityozx/sel/iterator"
import "github.com/xztaityozx/sel/src/iterator"

type Selector interface {
Select(w *Writer, iterator iterator.IEnumerable) error
10 changes: 5 additions & 5 deletions column/switch.go → src/column/switch.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"regexp"
"strconv"

"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"
)

type address struct {
@@ -50,17 +50,17 @@ func between(a, max, min int) int {
func (s SwitchSelector) Select(w *Writer, iter iterator.IEnumerable) error {
// isAroundContextなときは、配列の最大長が必要になるので、最初に全部分割してしまう
strings := iter.ToArray()
max := len(strings)
min := 0
maximum := len(strings)
minimum := 0
var rt []string
if s.end.isAroundContext {
for i, v := range strings {
if s.begin.match(v, i) {
// マッチした位置から前後どちらかにs.end.num個
if s.end.num < 0 {
rt = append(rt, strings[between(i+s.end.num, max, min):between(i+1, max, min)]...)
rt = append(rt, strings[between(i+s.end.num, maximum, minimum):between(i+1, maximum, minimum)]...)
} else {
rt = append(rt, strings[between(i, max, min):between(i+s.end.num+1, max, min)]...)
rt = append(rt, strings[between(i, maximum, minimum):between(i+s.end.num+1, maximum, minimum)]...)
}
}
}
10 changes: 5 additions & 5 deletions column/switch_test.go → src/column/switch_test.go
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ package column
import (
"bytes"
"github.com/stretchr/testify/assert"
"github.com/xztaityozx/sel/iterator"
"github.com/xztaityozx/sel/src/iterator"
"github.com/xztaityozx/sel/test_util"
"regexp"
"strings"
@@ -43,11 +43,11 @@ type testEnumerable struct {
a []string
}

func (t *testEnumerable) ResetFromArray(a []string) {
panic("implement me")
func (t *testEnumerable) ResetFromArray(_ []string) {
panic("implement me")
}

func (t *testEnumerable) ElementAt(idx int) (string, error) {
func (t *testEnumerable) ElementAt(_ int) (string, error) {
panic("implement me")
}

@@ -59,7 +59,7 @@ func (t *testEnumerable) Last() (item string, ok bool) {
panic("implement me")
}

func (t *testEnumerable) Reset(s string) {
func (t *testEnumerable) Reset(_ string) {
panic("implement me")
}

File renamed without changes.
File renamed without changes.
File renamed without changes
6 changes: 3 additions & 3 deletions iterator/iterator.go → src/iterator/iterator.go
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ import (
"regexp"
"strings"

"github.com/xztaityozx/sel/option"
"github.com/xztaityozx/sel/src/option"
)

type IEnumerable interface {
@@ -222,7 +222,7 @@ func (i *Iterator) ToArray() []string {
return a
}

func (i *Iterator) ResetFromArray(a []string) {
func (i *Iterator) ResetFromArray(_ []string) {
panic("not impl")
}

@@ -396,7 +396,7 @@ func (r *RegexpIterator) Reset(s string) {
r.a = nil
}

func (r *RegexpIterator) ResetFromArray(a []string) {
func (r *RegexpIterator) ResetFromArray(_ []string) {
panic("not impl")
}

Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/xztaityozx/sel/option"
"github.com/xztaityozx/sel/src/option"
)

func TestNewIterator(t *testing.T) {
File renamed without changes.
20 changes: 10 additions & 10 deletions iterator/presplit_test.go → src/iterator/presplit_test.go
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ func TestNewPreSplitByRegexpIterator(t *testing.T) {
removeEmpty: true,
}},
{name: "", args: args{s: "a11b22c33d", reg: regexp.MustCompile(`\d`), re: false}, want: &PreSplitIterator{
a: []string{"a", "", "b","", "c","", "d"},
a: []string{"a", "", "b", "", "c", "", "d"},
head: 0,
tail: 0,
reg: regexp.MustCompile(`\d`),
@@ -82,7 +82,7 @@ func TestNewPreSplitIterator(t *testing.T) {
removeEmpty: true,
}},
{name: "split by space(remove-empty)", args: args{s: "a b c d", sep: " ", re: false}, want: &PreSplitIterator{
a: []string{"a", "b","", "", "c", "d"},
a: []string{"a", "b", "", "", "c", "d"},
head: 0,
tail: 0,
sep: " ",
@@ -115,7 +115,7 @@ func TestPreSplitIterator_ToArray(t *testing.T) {
fields fields
want []string
}{
{name: "contained", fields: fields{a: []string{"a","b","c"}}, want: []string{"a","b","c"}},
{name: "contained", fields: fields{a: []string{"a", "b", "c"}}, want: []string{"a", "b", "c"}},
{name: "empty", fields: fields{a: nil}, want: nil},
}
for _, tt := range tests {
@@ -295,12 +295,12 @@ func TestPreSplitIterator_ElementAt(t *testing.T) {
want string
wantErr bool
}{
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 1}, want: "1", wantErr: false},
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 4}, want: "4", wantErr: false},
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 5}, want: "", wantErr: true},
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -5}, want: "", wantErr: true},
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -4}, want: "1", wantErr: false},
{name: "", fields: fields{a:[]string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -1}, want: "4", wantErr: false},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 1}, want: "1", wantErr: false},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 4}, want: "4", wantErr: false},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: 5}, want: "", wantErr: true},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -5}, want: "", wantErr: true},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -4}, want: "1", wantErr: false},
{name: "", fields: fields{a: []string{"1", "2", "3", "4"}, head: 0, tail: 0, sep: " ", reg: nil, l: 4, removeEmpty: false}, args: args{idx: -1}, want: "4", wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -323,4 +323,4 @@ func TestPreSplitIterator_ElementAt(t *testing.T) {
}
})
}
}
}
File renamed without changes.
5 changes: 3 additions & 2 deletions option/option_test.go → src/option/option_test.go
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import (
"github.com/spf13/viper"

"github.com/stretchr/testify/assert"
"github.com/xztaityozx/sel/option"
"github.com/xztaityozx/sel/src/option"
)

func TestInputFiles_Enumerate(t *testing.T) {
@@ -65,7 +65,8 @@ func TestInputFiles_Enumerate(t *testing.T) {
})

t.Run("スペシャルファイルはOpenできない", func(t *testing.T) {
if runtime.GOOS == "windows" {
if //goland:noinspection ALL
runtime.GOOS == "windows" {
t.Skip()
}
_, err := option.InputFiles{Files: []string{"/dev/null"}}.Enumerate()
Loading