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

Support goreleaser and show version flag #7

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions .github/workflows/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
debug
main
MpegTsAnalyzer

dist/
51 changes: 51 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -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:"
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [<flags>] <input>
usage: MpegTsAnalyzer [<flags>] [<input>]


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> Input file name.
[<input>] Input file name.
```

# Result Examples
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
16 changes: 15 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 }

Expand All @@ -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 }
16 changes: 16 additions & 0 deletions options/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}