mirror of https://github.com/harness/drone.git
[CLI] move swagger+server under cli/operations (#1011)
parent
b227b313d5
commit
c270b8f7b9
|
@ -18,7 +18,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/harness/gitness/cli/server"
|
||||
"github.com/harness/gitness/cli/operations/server"
|
||||
"github.com/harness/gitness/store/database"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package cli
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -22,24 +22,27 @@ import (
|
|||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
type swaggerCommand struct {
|
||||
path string
|
||||
type command struct {
|
||||
openAPIService openapi.Service
|
||||
path string
|
||||
}
|
||||
|
||||
func (c *swaggerCommand) run(*kingpin.ParseContext) error {
|
||||
openAPIGenerator := openapi.NewOpenAPIService()
|
||||
spec := openAPIGenerator.Generate()
|
||||
func (c *command) run(*kingpin.ParseContext) error {
|
||||
spec := c.openAPIService.Generate()
|
||||
data, _ := spec.MarshalYAML()
|
||||
if c.path == "" {
|
||||
os.Stdout.Write(data)
|
||||
return nil
|
||||
}
|
||||
|
||||
return os.WriteFile(c.path, data, 0o600)
|
||||
}
|
||||
|
||||
// helper function to register the swagger command.
|
||||
func RegisterSwagger(app *kingpin.Application) {
|
||||
c := new(swaggerCommand)
|
||||
func Register(app *kingpin.Application, openAPIService openapi.Service) {
|
||||
c := &command{
|
||||
openAPIService: openAPIService,
|
||||
}
|
||||
|
||||
cmd := app.Command("swagger", "generate swagger file").
|
||||
Hidden().
|
|
@ -15,13 +15,15 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/harness/gitness/app/api/openapi"
|
||||
"github.com/harness/gitness/cli"
|
||||
"github.com/harness/gitness/cli/operations/account"
|
||||
"github.com/harness/gitness/cli/operations/hooks"
|
||||
"github.com/harness/gitness/cli/operations/migrate"
|
||||
"github.com/harness/gitness/cli/operations/server"
|
||||
"github.com/harness/gitness/cli/operations/swagger"
|
||||
"github.com/harness/gitness/cli/operations/user"
|
||||
"github.com/harness/gitness/cli/operations/users"
|
||||
"github.com/harness/gitness/cli/server"
|
||||
"github.com/harness/gitness/version"
|
||||
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
|
@ -49,7 +51,7 @@ func main() {
|
|||
|
||||
hooks.Register(app)
|
||||
|
||||
cli.RegisterSwagger(app)
|
||||
swagger.Register(app, openapi.NewOpenAPIService())
|
||||
|
||||
kingpin.Version(version.Version.String())
|
||||
kingpin.MustParse(app.Parse(args))
|
||||
|
|
|
@ -73,7 +73,7 @@ import (
|
|||
"github.com/harness/gitness/app/store/logs"
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/blob"
|
||||
cliserver "github.com/harness/gitness/cli/server"
|
||||
cliserver "github.com/harness/gitness/cli/operations/server"
|
||||
"github.com/harness/gitness/encrypt"
|
||||
"github.com/harness/gitness/events"
|
||||
"github.com/harness/gitness/git"
|
||||
|
|
|
@ -72,7 +72,7 @@ import (
|
|||
"github.com/harness/gitness/app/store/logs"
|
||||
"github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/blob"
|
||||
"github.com/harness/gitness/cli/server"
|
||||
"github.com/harness/gitness/cli/operations/server"
|
||||
"github.com/harness/gitness/encrypt"
|
||||
"github.com/harness/gitness/events"
|
||||
"github.com/harness/gitness/git"
|
||||
|
|
Loading…
Reference in New Issue