Skip to content

Commit 8d9e83e

Browse files
committed
chore: release init command stub
1 parent c86b4ea commit 8d9e83e

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package languagecontainer defines LanguageContainer interface and
16+
// the Run function to execute commands within the container.
17+
// This package should not have any language-specific implementation or
18+
// Librarian CLI's implementation.
19+
// TODO(b/447404382): Move this package to the https://github.com/googleapis/librarian
20+
// GitHub repository once the interface is finalized.
21+
package languagecontainer
22+
23+
import (
24+
"context"
25+
"log/slog"
26+
27+
"cloud.google.com/java/internal/librariangen/languagecontainer/release"
28+
"cloud.google.com/java/internal/librariangen/message"
29+
)
30+
31+
// LanguageContainer defines the interface for language-specific container operations.
32+
type LanguageContainer interface {
33+
ReleaseInit(context.Context, *release.Config) (*message.ReleaseInitResponse, error)
34+
// Other container functions like Generate and Build will also be part of the interface.
35+
}
36+
37+
// Run would accept an implementation of the LanguageContainer interface.
38+
func Run(args []string, container LanguageContainer) int {
39+
// Logic to parse args and call the appropriate method on the container.
40+
// For example, if args[1] is "generate":
41+
// request := ... // unmarshal the request from the expected location
42+
// err := container.Generate(context.Background(), request)
43+
// ...
44+
if len(args) < 1 {
45+
panic("args must not be empty")
46+
}
47+
switch args[0] {
48+
case "generate":
49+
slog.Warn("librariangen: generate command is not yet implemented")
50+
return 1
51+
case "configure":
52+
slog.Warn("librariangen: configure command is not yet implemented")
53+
return 1
54+
case "release-init":
55+
// TODO: Parse flags and read request from the release-init-request.json file
56+
// Create release.Config object.
57+
58+
// TODO: Call container's ReleaseInit method with the parsed request
59+
60+
// TODO: Save the response to release-init-response.json file
61+
slog.Info("librariangen: release-init command executed successfully")
62+
case "build":
63+
slog.Warn("librariangen: build command is not yet implemented")
64+
return 1
65+
default:
66+
slog.Error("librariangen: unknown command: %s (with flags %v)", args[0], args)
67+
return 1
68+
}
69+
return 0
70+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package release
2+
3+
import "cloud.google.com/java/internal/librariangen/message"
4+
5+
// The ReleaseInitContext has the directory paths for the release-init command.
6+
// https://github.com/googleapis/librarian/blob/main/doc/language-onboarding.md#release-init
7+
type ReleaseInitContext struct {
8+
LibrarianDir string
9+
RepoDir string
10+
OutputDir string
11+
}
12+
13+
type Config struct {
14+
Context *ReleaseInitContext
15+
// This request is parsed from the release-init-request.json file in
16+
// the LibrarianDir of the context.
17+
Request *message.ReleaseInitRequest
18+
}

0 commit comments

Comments
 (0)