Skip to content

Commit

Permalink
feat: add job creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ViolaPioggia committed Jul 7, 2024
1 parent f95a304 commit abe176c
Show file tree
Hide file tree
Showing 7 changed files with 591 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cmd/static/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/cloudwego/cwgo/pkg/consts"
"github.com/cloudwego/cwgo/pkg/curd/doc"
"github.com/cloudwego/cwgo/pkg/fallback"
"github.com/cloudwego/cwgo/pkg/job"
"github.com/cloudwego/cwgo/pkg/model"
"github.com/cloudwego/cwgo/pkg/server"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -95,6 +96,17 @@ func Init() *cli.App {
return doc.Doc(globalArgs.DocArgument)
},
},
{
Name: JobName,
Usage: JobUsage,
Flags: jobFlags(),
Action: func(c *cli.Context) error {
if err := globalArgs.JobArgument.ParseCli(c); err != nil {
return err
}
return job.Job(globalArgs.JobArgument)
},
},
{
Name: ApiListName,
Usage: ApiUsage,
Expand Down Expand Up @@ -197,7 +209,12 @@ Examples:
Examples:
cwgo api --project_path ./
`
JobName = "job"
JobUsage = `generate job code
Examples:
cwgo job --job_name jobOne --job_name jobTwo --module my_job
`
FallbackName = "fallback"
FallbackUsage = "fallback to hz or kitex"

Expand Down
14 changes: 14 additions & 0 deletions cmd/static/job_flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package static

import (
"github.com/cloudwego/cwgo/pkg/consts"
"github.com/urfave/cli/v2"
)

func jobFlags() []cli.Flag {
return []cli.Flag{
&cli.StringSliceFlag{Name: consts.JobName, Usage: "Specify the job name."},
&cli.StringFlag{Name: consts.Module, Aliases: []string{"mod"}, Usage: "Specify the Go module name to generate go.mod."},
&cli.StringFlag{Name: consts.OutDir, Usage: "Specify output directory, default is current dir."},
}
}
2 changes: 2 additions & 0 deletions config/argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type Argument struct {
*ClientArgument
*ModelArgument
*DocArgument
*JobArgument
*ApiArgument
*FallbackArgument
}
Expand All @@ -48,6 +49,7 @@ func NewArgument() *Argument {
ClientArgument: NewClientArgument(),
ModelArgument: NewModelArgument(),
DocArgument: NewDocArgument(),
JobArgument: NewJobArgument(),
ApiArgument: NewApiArgument(),
FallbackArgument: NewFallbackArgument(),
}
Expand Down
40 changes: 40 additions & 0 deletions config/job.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2024 CloudWeGo 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 config

import (
"github.com/cloudwego/cwgo/pkg/consts"
"github.com/urfave/cli/v2"
)

type JobArgument struct {
GoMod string
PackagePrefix string
JobName []string
OutDir string
}

func NewJobArgument() *JobArgument {
return &JobArgument{}
}

func (j *JobArgument) ParseCli(ctx *cli.Context) error {
j.JobName = ctx.StringSlice(consts.JobName)
j.GoMod = ctx.String(consts.Module)
j.OutDir = ctx.String(consts.OutDir)
return nil
}
4 changes: 4 additions & 0 deletions pkg/consts/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ const (
MongoDb = "mongodb"
)

const (
JobName = "job_name"
)

const (
BashAutocomplete = `#! /bin/bash
Expand Down
Loading

0 comments on commit abe176c

Please sign in to comment.