Skip to content
This repository has been archived by the owner on Feb 17, 2024. It is now read-only.

timecraft: add describe command #30

Merged
merged 4 commits into from
May 29, 2023
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
18 changes: 13 additions & 5 deletions format/timecraft.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,20 @@ func SHA256(b []byte) Hash {
}
}

func ParseHash(s string) (h Hash, err error) {
var ok bool
h.Algorithm, h.Digest, ok = strings.Cut(s, ":")
func ParseHash(s string) Hash {
algorithm, digest, ok := strings.Cut(s, ":")
if !ok {
err = fmt.Errorf("malformed hash: %s", s)
algorithm, digest = "sha256", s
}
return h, err
return Hash{Algorithm: algorithm, Digest: digest}
}

func (h Hash) Short() string {
s := h.Digest
if len(s) > 12 {
s = s[:12]
}
return s
}

func (h Hash) String() string {
Expand Down Expand Up @@ -123,6 +130,7 @@ func (m *Module) UnmarshalResource(b []byte) error {
}

type Runtime struct {
Runtime string `json:"runtime" yaml:"runtime"`
Version string `json:"version" yaml:"version"`
}

Expand Down
Loading
Loading