From 0a000b5fb85102753f778523da4d68349f3d464c Mon Sep 17 00:00:00 2001 From: matsuuram Date: Fri, 1 Dec 2023 23:17:18 +0900 Subject: [PATCH] Support goreleaser and show version flag --- .github/workflows/goreleaser.yml | 28 ++++++++++++++++++ .gitignore | 2 ++ .goreleaser.yaml | 51 ++++++++++++++++++++++++++++++++ README.md | 21 +++++++------ go.mod | 3 +- go.sum | 7 +++++ main.go | 16 +++++++++- options/options.go | 9 +++++- options/options_test.go | 16 ++++++++++ 9 files changed, 141 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/goreleaser.yml create mode 100644 .goreleaser.yaml diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml new file mode 100644 index 0000000..e8a97cb --- /dev/null +++ b/.github/workflows/goreleaser.yml @@ -0,0 +1,28 @@ +name: goreleaser + +on: + push: + tags: + - "*" +jobs: + goreleaser: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - + name: Set up Go + uses: actions/setup-go@v4 + with: + go-version-file: './go.mod' + - + name: Run GoReleaser + uses: goreleaser/goreleaser-action@v5 + with: + version: latest + args: release --clean + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 8697e85..20f190d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ debug main MpegTsAnalyzer + +dist/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..b6d8c11 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,51 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +# The lines below are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/need to use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +version: 1 + +before: + hooks: + # You may remove this if you don't use go modules. + - go mod tidy + # you may remove this if you don't need go generate + - go generate ./... + +builds: + - env: + - CGO_ENABLED=0 + goos: + - linux + - windows + - darwin + flags: + - -trimpath + ldflags: + - -s -w + - -X main.version={{.Version}} + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of `uname`. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + filters: + exclude: + - "^docs:" + - "^test:" diff --git a/README.md b/README.md index 97d2ff8..ebe788d 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,22 @@ It can parse TS header, Adaptation Field, PSI(PAT/PMT) and PES header. Then, it Default, it is dump each timestamps(PCR/PTS/DTS) that include PCR interval and PTS PCR gap. If you want to dump more detail, please add each command line flags. ``` -usage: MpegTsAnalyzer [] +usage: MpegTsAnalyzer [] [] + Flags: - --help Show context-sensitive help (also try --help-long - and --help-man). - --dump-ts-header Dump TS packet header. - --dump-ts-payload Dump TS packet payload binary. - --dump-adaptation-field Dump TS packet adaptation_field detail. - --dump-psi Dump PSI(PAT/PMT) detail. - -t, --dump-timestamp Dump PCR/PTS/DTS timestamps. + --[no-]help Show context-sensitive help (also try --help-long and --help-man). + --[no-]dump-ts-header Dump TS packet header. + --[no-]dump-ts-payload Dump TS packet payload binary. + --[no-]dump-adaptation-field + Dump TS packet adaptation_field detail. + --[no-]dump-psi Dump PSI(PAT/PMT) detail. + --[no-]dump-pes-header Dump PES packet header detail. + -t, --[no-]dump-timestamp Dump PCR/PTS/DTS timestamps. + --[no-]version Show app version. Args: - Input file name. + [] Input file name. ``` # Result Examples diff --git a/go.mod b/go.mod index 1fd4fe6..40799a8 100644 --- a/go.mod +++ b/go.mod @@ -2,8 +2,9 @@ module github.com/small-teton/MpegTsAnalyzer go 1.21.4 +require github.com/alecthomas/kingpin/v2 v2.4.0 + require ( - github.com/alecthomas/kingpin/v2 v2.4.0 // indirect github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect github.com/xhit/go-str2duration/v2 v2.1.0 // indirect ) diff --git a/go.sum b/go.sum index 5dad70b..326c8c9 100644 --- a/go.sum +++ b/go.sum @@ -3,10 +3,17 @@ github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HR github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc= github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= +github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc= github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index ab462da..6feb620 100644 --- a/main.go +++ b/main.go @@ -19,10 +19,13 @@ var ( dumpPsi = kingpin.Flag("dump-psi", "Dump PSI(PAT/PMT) detail.").Bool() dumpPesHeader = kingpin.Flag("dump-pes-header", "Dump PES packet header detail.").Bool() dumpTimestamp = kingpin.Flag("dump-timestamp", "Dump PCR/PTS/DTS timestamps.").Short('t').Bool() + showVersion = kingpin.Flag("version", "Show app version.").Bool() ) +var version string + func main() { - filename := kingpin.Arg("input", "Input file name.").Required().String() + filename := kingpin.Arg("input", "Input file name.").String() kingpin.Parse() var options options.Options @@ -32,6 +35,17 @@ func main() { options.SetDumpPsi(*dumpPsi) options.SetDumpPesHeader(*dumpPesHeader) options.SetDumpTimestamp(*dumpTimestamp) + options.SetVersion(*showVersion) + + if options.Version() { + fmt.Printf("version: %s\n", version) + os.Exit(0) + } + + if *filename == "" { + fmt.Println("input file name is empty.") + os.Exit(1) + } if err := parseTsFile(*filename, options); err != nil { fmt.Println(err) diff --git a/options/options.go b/options/options.go index c19e224..25028ed 100644 --- a/options/options.go +++ b/options/options.go @@ -7,7 +7,8 @@ type Options struct { dumpAdaptationField bool dumpPsi bool dumpPesHeader bool - dumpTimestamp bool + dumpTimestamp bool + version bool } // DumpHeader return flag data "--dump-ts-header" @@ -28,6 +29,9 @@ func (o *Options) DumpPesHeader() bool { return o.dumpPesHeader } // NotDumpTimestamp return flag data "--not-dump-timestamp" func (o *Options) DumpTimestamp() bool { return o.dumpTimestamp } +// NotDumpTimestamp return flag data "--not-dump-timestamp" +func (o *Options) Version() bool { return o.version } + // SetDumpHeader set value to "--dump-ts-header" func (o *Options) SetDumpHeader(v bool) { o.dumpHeader = v } @@ -45,3 +49,6 @@ func (o *Options) SetDumpPesHeader(v bool) { o.dumpPesHeader = v } // SetDumpTimestamp set value to "--dump-timestamp" func (o *Options) SetDumpTimestamp(v bool) { o.dumpTimestamp = v } + +// SetVersion set value to "--version" +func (o *Options) SetVersion(v bool) { o.version = v } diff --git a/options/options_test.go b/options/options_test.go index 6d1330a..c986301 100644 --- a/options/options_test.go +++ b/options/options_test.go @@ -193,3 +193,19 @@ func TestDumpTimestamp(t *testing.T) { t.Errorf("actual: false, But got %t", retVal) } } + +func TestVersion(t *testing.T) { + options := new(Options) + + options.SetVersion(true) + retVal := options.version + if retVal != true { + t.Errorf("actual: true, But got %t", retVal) + } + + options.SetVersion(false) + retVal = options.version + if retVal != false { + t.Errorf("actual: false, But got %t", retVal) + } +}