Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state publish #2950

Closed
wants to merge 3 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions cmd/state/internal/cmdtree/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func newBundleUninstallCommand(prime *primer.Values) *captain.Command {
{
Name: locale.T("bundle_arg_name"),
Description: locale.T("bundle_arg_name_description"),
Value: &params.Name,
Value: &params.Package,
Required: true,
},
},
Expand Down Expand Up @@ -118,7 +118,7 @@ func newBundlesSearchCommand(prime *primer.Values) *captain.Command {
{
Name: locale.T("bundle_arg_name"),
Description: locale.T("bundle_arg_name_description"),
Value: &params.Name,
Value: &params.Ingredient,
Required: true,
},
},
Expand Down
2 changes: 2 additions & 0 deletions cmd/state/internal/cmdtree/cmdtree.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ func New(prime *primer.Values, args ...string) *CmdTree {
refreshCmd,
newSwitchCommand(prime),
newTestCommand(prime),
newPublish(prime),
//newCommitCommand(prime), // re-enable in DX-2307
)

Expand All @@ -230,6 +231,7 @@ var (
VCSGroup = captain.NewCommandGroup(locale.Tl("group_vcs", "Version Control"), 5)
AutomationGroup = captain.NewCommandGroup(locale.Tl("group_automation", "Automation"), 4)
UtilsGroup = captain.NewCommandGroup(locale.Tl("group_utils", "Utilities"), 3)
AuthorGroup = captain.NewCommandGroup(locale.Tl("group_author", "Author"), 6)
)

func newGlobalOptions() *globalOptions {
Expand Down
22 changes: 19 additions & 3 deletions cmd/state/internal/cmdtree/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ func newInstallCommand(prime *primer.Values) *captain.Command {
locale.Tl("package_install_title", "Installing Package"),
locale.T("package_install_cmd_description"),
prime,
[]*captain.Flag{},
[]*captain.Flag{
{
Name: "ts",
Description: locale.T("package_flag_ts_description"),
Value: &params.Timestamp,
},
},
[]*captain.Argument{
{
Name: locale.T("package_arg_nameversion"),
Expand Down Expand Up @@ -88,7 +94,7 @@ func newUninstallCommand(prime *primer.Values) *captain.Command {
{
Name: locale.T("package_arg_name"),
Description: locale.T("package_arg_name_description"),
Value: &params.Name,
Value: &params.Package,
Required: true,
},
},
Expand Down Expand Up @@ -145,12 +151,17 @@ func newSearchCommand(prime *primer.Values) *captain.Command {
Description: locale.T("package_search_flag_exact-term_description"),
Value: &params.ExactTerm,
},
{
Name: "ts",
Description: locale.T("package_search_flag_ts_description"),
Value: &params.Timestamp,
},
},
[]*captain.Argument{
{
Name: locale.T("package_arg_name"),
Description: locale.T("package_arg_name_description"),
Value: &params.Name,
Value: &params.Ingredient,
Required: true,
},
},
Expand All @@ -176,6 +187,11 @@ func newInfoCommand(prime *primer.Values) *captain.Command {
Description: locale.T("package_info_flag_language_description"),
Value: &params.Language,
},
{
Name: "ts",
Description: locale.T("package_flag_ts_description"),
Value: &params.Timestamp,
},
},
[]*captain.Argument{
{
Expand Down
97 changes: 97 additions & 0 deletions cmd/state/internal/cmdtree/publish.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package cmdtree

import (
"github.com/ActiveState/cli/internal/captain"
"github.com/ActiveState/cli/internal/locale"
"github.com/ActiveState/cli/internal/primer"
"github.com/ActiveState/cli/internal/runners/publish"
)

func newPublish(prime *primer.Values) *captain.Command {
runner := publish.New(prime)
params := publish.Params{}
c := captain.NewCommand(
"publish",
locale.Tl("add_title", "Publish Ingredient"),
locale.Tl("add_description", "Publish an Ingredient for private consumption."),
prime,
[]*captain.Flag{
{
Name: "edit",
Description: locale.Tl("author_upload_edit_description", "Create a revision for an existing ingredient, matched by their name and namespace."),
Value: &params.Edit,
},
{
Name: "editor",
Description: locale.Tl("author_upload_editor_description", "Edit the ingredient information in your editor before uploading."),
Value: &params.Editor,
},
{
Name: "name",
Description: locale.Tl(
"author_upload_name_description",
"The name of the ingredient. Defaults to basename of filepath.",
),
Value: &params.Name,
},
{
Name: "version",
Description: locale.Tl(
"author_upload_version_description",
"Version of the ingredient (preferably semver).",
),
Value: &params.Version,
},
{
Name: "namespace",
Description: locale.Tl(
"author_upload_namespace_description",
"The namespace of the ingredient. Defaults to org/<orgname>. Must start with 'org/<orgname>'.",
),
Value: &params.Namespace,
},
{
Name: "description",
Description: locale.Tl(
"author_upload_description_description",
"A short description summarizing what this ingredient is for.",
),
Value: &params.Description,
},
{
Name: "author",
Description: locale.Tl(
"author_upload_author_description",
"Ingredient author, in the format of \"[<name>] <email>\". Can be set multiple times.",
),
Value: &params.Authors,
},
{
Name: "depend",
Description: locale.Tl(
"author_upload_depend_description",
"Ingredient that this ingredient depends on, format as <namespace>/<name>[@<version>]. Can be set multiple times.",
),
Value: &params.Depends,
},
{
Name: "meta",
Description: locale.Tl("author_upload_metafile_description", "A yaml file expressing the ingredient meta information. Use --editor to review the file format."),
Value: &params.MetaFilepath,
},
},
[]*captain.Argument{
{
Name: locale.Tl("filepath", "filepath"),
Description: locale.Tl("author_upload_filepath_description", "A tar.gz or zip archive containing the source files of the ingredient."),
Value: &params.Filepath,
Required: true,
},
},
func(_ *captain.Command, _ []string) error {
return runner.Run(&params)
})
c.SetGroup(AuthorGroup)
c.SetUnstable(true)
return c
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pelletier/go-toml v1.7.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
Expand Down
14 changes: 8 additions & 6 deletions internal/assets/contents/usage.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ Examples:
{{- end }}

{{- childCommands .Cmd}}
{{- if gt (len .Cmd.Arguments) 0}}

Arguments:
{{- range .Cmd.Arguments }}
<{{ .Name }}> {{ if .Required }} {{ else }}(optional){{ end }} {{ .Description }}
{{- end }}
{{- end }}

{{- if .Cobra.HasAvailableFlags}}

Flags:
Expand All @@ -31,13 +39,7 @@ Flags:
Global Flags:
{{.Cobra.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}
{{- end}}
{{- if gt (len .Cmd.Arguments) 0}}

Arguments:
{{- range .Cmd.Arguments }}
<{{ .Name }}> {{ if .Required }} {{ else }}(optional){{ end }} {{ .Description }}
{{- end }}
{{- end}}
{{- if .Cobra.HasHelpSubCommands}}

Additional help topics:
Expand Down
13 changes: 7 additions & 6 deletions internal/captain/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@ import (
"strings"

"github.com/ActiveState/cli/internal/errs"
"github.com/spf13/pflag"
)

type FlagMarshaler interface {
String() string
Set(string) error
Type() string
}
type FlagMarshaler pflag.Value

// Flag is used to define flags in our Command struct
type Flag struct {
Expand All @@ -38,6 +35,10 @@ func (c *Command) setFlags(flags []*Flag) error {
switch v := flag.Value.(type) {
case nil:
return errs.New("flag value must not be nil (%v)", flag)
case *[]string:
flagSetter().StringSliceVarP(
v, flag.Name, flag.Shorthand, *v, flag.Description,
)
case *string:
flagSetter().StringVarP(
v, flag.Name, flag.Shorthand, *v, flag.Description,
Expand All @@ -56,7 +57,7 @@ func (c *Command) setFlags(flags []*Flag) error {
)
default:
return errs.New(
fmt.Sprintf("Unknown type: %s (%v)"+reflect.TypeOf(v).Name(), v),
fmt.Sprintf("Unknown type for flag %s: %s (%v)", flag.Name, reflect.TypeOf(v).Name(), v),
)
}

Expand Down
40 changes: 0 additions & 40 deletions internal/captain/nameversion.go

This file was deleted.

Loading
Loading