Skip to content

Commit

Permalink
content authoring wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iximiuz committed Mar 17, 2024
1 parent 550b2e6 commit 5ebdfde
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
7 changes: 6 additions & 1 deletion cmd/content/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func newCreateCommand(cli labcli.CLI) *cobra.Command {
opts.dir = filepath.Join(cwd, opts.name)
}
}
if absDir, err := filepath.Abs(opts.dir); err != nil {
return labcli.WrapStatusError(fmt.Errorf("couldn't get the absolute path of %s: %w", opts.dir, err))
} else {
opts.dir = absDir
}

return labcli.WrapStatusError(runCreateContent(cmd.Context(), cli, &opts))
},
Expand Down Expand Up @@ -127,7 +132,7 @@ func createChallenge(ctx context.Context, cli labcli.CLI, opts *createOptions) e

if err := cli.Client().PutMarkdown(ctx, api.PutMarkdownRequest{
Kind: "challenge",
Name: opts.name,
Name: ch.Name,
Content: `---
title: Sample Challenge 444
description: |
Expand Down
7 changes: 4 additions & 3 deletions cmd/content/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func newListCommand(cli labcli.CLI) *cobra.Command {
var opts listOptions

cmd := &cobra.Command{
Use: "list [--kind challenge|tutorial|course]",
Short: "List authored content, possibly filtered by kind.",
Args: cobra.NoArgs,
Use: "list [--kind challenge|tutorial|course]",
Aliases: []string{"ls"},
Short: "List authored content, possibly filtered by kind.",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return labcli.WrapStatusError(runListContent(cmd.Context(), cli, &opts))
},
Expand Down
21 changes: 16 additions & 5 deletions cmd/content/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ func newRemoveCommand(cli labcli.CLI) *cobra.Command {
var opts removeOptions

cmd := &cobra.Command{
Use: "remove [flags] <challenge|tutorial|course> <name>",
Short: "Remove a piece of content you authored.",
Args: cobra.ExactArgs(2),
Use: "remove [flags] <challenge|tutorial|course> <name>",
Aliases: []string{"rm"},
Short: "Remove a piece of content you authored.",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
if err := opts.kind.Set(args[0]); err != nil {
return labcli.WrapStatusError(err)
Expand All @@ -32,13 +33,23 @@ func newRemoveCommand(cli labcli.CLI) *cobra.Command {
},
}

flags := cmd.Flags()

flags.BoolVarP(
&opts.force,
"force",
"f",
false,
"Remove without confirmation.",
)

return cmd
}

func runRemoveContent(ctx context.Context, cli labcli.CLI, opts *removeOptions) error {
cli.PrintAux("Removing %s %s...\n", opts.kind, opts.name)

if !opts.force {
cli.PrintAux("Removing %s %s...\n", opts.kind, opts.name)

if !cli.Confirm(
"This action is irreversible. Are you sure?",
"Yes", "No",
Expand Down

0 comments on commit 5ebdfde

Please sign in to comment.