-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Xiaoxuan Wang <[email protected]>
- Loading branch information
Xiaoxuan Wang
committed
Sep 25, 2024
1 parent
5104cc9
commit a9b1164
Showing
7 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright The ORAS Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package content | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
|
||
"oras.land/oras/cmd/oras/internal/output" | ||
) | ||
|
||
// manifestIndexCreate handles raw content output. | ||
type manifestIndexCreate struct { | ||
pretty bool | ||
stdout io.Writer | ||
outputPath string | ||
} | ||
|
||
// OnContentCreated is called after index content is created. | ||
func (h *manifestIndexCreate) OnContentCreated(manifest []byte) error { | ||
out := h.stdout | ||
if h.outputPath != "-" && h.outputPath != "" { | ||
f, err := os.Create(h.outputPath) | ||
if err != nil { | ||
return fmt.Errorf("failed to open %q: %w", h.outputPath, err) | ||
} | ||
defer f.Close() | ||
out = f | ||
} | ||
return output.PrintJSON(out, manifest, h.pretty) | ||
} | ||
|
||
// NewManifestIndexCreateHandler creates a new handler. | ||
func NewManifestIndexCreateHandler(out io.Writer, pretty bool, outputPath string) ManifestIndexCreateHandler { | ||
return &manifestIndexCreate{ | ||
pretty: pretty, | ||
stdout: out, | ||
outputPath: outputPath, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters