Skip to content

Commit

Permalink
doc,fq: Improve cli help and some cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wader committed Feb 15, 2023
1 parent 9bad378 commit a1bb630
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 31 deletions.
2 changes: 1 addition & 1 deletion format/bitcoin/bitcoin_blkdat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
})
}

func decodeBlkDat(d *decode.D, in interface{}) interface{} {
func decodeBlkDat(d *decode.D, in any) any {
validBlocks := 0
for !d.End() {
d.FieldFormat("block", bitcoinBlockFormat, format.BitCoinBlockIn{HasHeader: true})
Expand Down
2 changes: 1 addition & 1 deletion format/bitcoin/bitcoin_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var rawHexReverse = scalar.BitBufFn(func(s scalar.BitBuf) (scalar.BitBuf, error)
})
})

func decodeBitcoinBlock(d *decode.D, in interface{}) interface{} {
func decodeBitcoinBlock(d *decode.D, in any) any {
bbi, _ := in.(format.BitCoinBlockIn)
size := d.BitsLeft()

Expand Down
2 changes: 1 addition & 1 deletion format/bitcoin/bitcoin_script.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
})
}

func decodeBitcoinScript(d *decode.D, in interface{}) interface{} {
func decodeBitcoinScript(d *decode.D, in any) any {
// based on https://en.bitcoin.it/wiki/Script
opcodeEntries := opcodeEntries{
{r: [2]byte{0x00, 0x00}, s: scalar.Uint{Sym: "false"}},
Expand Down
2 changes: 1 addition & 1 deletion format/bitcoin/bitcoin_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func decodeVarInt(d *decode.D) uint64 {
// all zero
var txIDCoinbaseBytes = [32]byte{}

func decodeBitcoinTranscation(d *decode.D, in interface{}) interface{} {
func decodeBitcoinTranscation(d *decode.D, in any) any {
d.Endian = decode.LittleEndian

d.FieldU32("version")
Expand Down
10 changes: 5 additions & 5 deletions format/mp4/testdata/pssh.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ $ fq ddv pssh.mp4
| | | wire_type: "varint" (0) 0x49f-NA (0)
0x490| 01| .| wire_value: 1 0x49f-0x49f.7 (1)
| | | name: "algorithm" 0x4a0-NA (0)
| | | type: "Enum" 0x4a0-NA (0)
| | | type: "enum" 0x4a0-NA (0)
| | | enum: "aesctr" 0x4a0-NA (0)
| | | [1]{}: field 0x4a0-0x4b1.7 (18)
0x4a0|12 |. | key_n: 18 0x4a0-0x4a0.7 (1)
Expand All @@ -122,7 +122,7 @@ $ fq ddv pssh.mp4
0x4a0| 88 37 80 c4 a9 81 49 4c b9 94 9e 93 79 2f| .7....IL....y/| wire_value: raw bits 0x4a2-0x4b1.7 (16)
0x4b0|f8 a7 |.. |
| | | name: "key_id" 0x4b2-NA (0)
| | | type: "Bytes" 0x4b2-NA (0)
| | | type: "bytes" 0x4b2-NA (0)
| | | value: raw bits 0x4b2-NA (0)
| | | [2]{}: field 0x4b2-0x4c0.7 (15)
0x4b0| 1a | . | key_n: 26 0x4b2-0x4b2.7 (1)
Expand All @@ -132,7 +132,7 @@ $ fq ddv pssh.mp4
0x4b0| 77 69 64 65 76 69 6e 65 5f 74 65 73| widevine_tes| wire_value: raw bits 0x4b4-0x4c0.7 (13)
0x4c0|74 |t |
| | | name: "provider" 0x4c1-NA (0)
| | | type: "String" 0x4c1-NA (0)
| | | type: "string" 0x4c1-NA (0)
| | | value: "widevine_test" 0x4c1-NA (0)
| | | [3]{}: field 0x4c1-0x4ca.7 (10)
0x4c0| 22 | " | key_n: 34 0x4c1-0x4c1.7 (1)
Expand All @@ -141,7 +141,7 @@ $ fq ddv pssh.mp4
0x4c0| 08 | . | length: 8 0x4c2-0x4c2.7 (1)
0x4c0| 31 32 33 34 35 36 37 38 | 12345678 | wire_value: raw bits 0x4c3-0x4ca.7 (8)
| | | name: "content_id" 0x4cb-NA (0)
| | | type: "Bytes" 0x4cb-NA (0)
| | | type: "bytes" 0x4cb-NA (0)
| | | value: raw bits 0x4cb-NA (0)
| | | [4]{}: field 0x4cb-0x4d3.7 (9)
0x4c0| 32 | 2 | key_n: 50 0x4cb-0x4cb.7 (1)
Expand All @@ -151,5 +151,5 @@ $ fq ddv pssh.mp4
0x4c0| 64 65 66| def| wire_value: raw bits 0x4cd-0x4d3.7 (7)
0x4d0|61 75 6c 74| |ault| |
| | | name: "policy" 0x4d4-NA (0)
| | | type: "String" 0x4d4-NA (0)
| | | type: "string" 0x4d4-NA (0)
| | | value: "default" 0x4d4-NA (0)
36 changes: 18 additions & 18 deletions format/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,24 @@ const (
)

var ProtoBufTypeNames = scalar.UintMapSymStr{
ProtoBufTypeInt32: "Int32",
ProtoBufTypeInt64: "Int64",
ProtoBufTypeUInt32: "UInt32",
ProtoBufTypeUInt64: "UInt64",
ProtoBufTypeSInt32: "SInt32",
ProtoBufTypeSInt64: "SInt64",
ProtoBufTypeBool: "Bool",
ProtoBufTypeEnum: "Enum",
ProtoBufTypeFixed64: "Fixed64",
ProtoBufTypeSFixed64: "SFixed64",
ProtoBufTypeDouble: "Double",
ProtoBufTypeString: "String",
ProtoBufTypeBytes: "Bytes",
ProtoBufTypeMessage: "Message",
ProtoBufTypePackedRepeated: "PackedRepeated",
ProtoBufTypeFixed32: "Fixed32",
ProtoBufTypeSFixed32: "SFixed32",
ProtoBufTypeFloat: "Float",
ProtoBufTypeInt32: "int32",
ProtoBufTypeInt64: "int64",
ProtoBufTypeUInt32: "uint32",
ProtoBufTypeUInt64: "uint64",
ProtoBufTypeSInt32: "sint32",
ProtoBufTypeSInt64: "sint64",
ProtoBufTypeBool: "bool",
ProtoBufTypeEnum: "enum",
ProtoBufTypeFixed64: "fixed64",
ProtoBufTypeSFixed64: "sfixed64",
ProtoBufTypeDouble: "double",
ProtoBufTypeString: "string",
ProtoBufTypeBytes: "bytes",
ProtoBufTypeMessage: "message",
ProtoBufTypePackedRepeated: "packed_repeated",
ProtoBufTypeFixed32: "fixed32",
ProtoBufTypeSFixed32: "sfixed32",
ProtoBufTypeFloat: "float",
}

type ProtoBufField struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/gojqex/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (err *ArrayIndexTooLargeError) Error() string {
return fmt.Sprintf("array index too large: %v", err.V)
}

func TypeErrorPreview(v interface{}) string {
func TypeErrorPreview(v any) string {
switch v.(type) {
case nil:
return "null"
Expand Down
6 changes: 5 additions & 1 deletion pkg/interp/.jq-lsp.jq
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ def _tovalue($opts): empty;
def open: empty;
def scope: empty;

# TODO: some functions below are from format/* refactor somehow?

# used by help.jq
def to_jq: empty;
def markdown: empty;
def _markdown_to_text($width; $header_depth): empty;
# used by funcs.jq iprint
def to_radix($base): empty;
def to_radix($base): empty;
2 changes: 1 addition & 1 deletion pkg/interp/options.jq
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _opt_cli_opts:
"show_help": {
short: "-h",
long: "--help",
description: "Show help for TOPIC (ex: --help, --help formats)",
description: "Show help for TOPIC (ex: --help, -h formats, -h mp4)",
string: "[TOPIC]",
optional: true
},
Expand Down
2 changes: 1 addition & 1 deletion pkg/interp/testdata/args.fqtest
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Example usages:
--compact-output,-c Compact output
--decode,-d NAME Decode format (probe)
--from-file,-f PATH Read EXPR from file
--help,-h [TOPIC] Show help for TOPIC (ex: --help, --help formats)
--help,-h [TOPIC] Show help for TOPIC (ex: --help, -h formats, -h mp4)
--include-path,-L PATH Include search path
--join-output,-j No newline between outputs
--monochrome-output,-M Force monochrome output
Expand Down

0 comments on commit a1bb630

Please sign in to comment.