Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion cmd/describe.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package cmd

import (
"context"
"encoding/json"
"encoding/xml"
"errors"
"fmt"
"io"
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/ory/viper"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"


"knative.dev/func/pkg/config"
fn "knative.dev/func/pkg/functions"
Expand Down Expand Up @@ -66,7 +69,11 @@
if err != nil {
return
}
// TODO cfg.Prompt()
if cfg.Name == "" && cfg.Path == "" {
if err := cfg.Prompt(newClient); err != nil {
return err
}
}

client, done := newClient(ClientConfig{Verbose: cfg.Verbose})
defer done()
Expand Down Expand Up @@ -133,6 +140,41 @@
return
}

// Prompt interactively asks the user to select a function name
// if none was provided via args or flags.
func (c *describeConfig) Prompt(newClient ClientFactory) error {
client, done := newClient(ClientConfig{Verbose: c.Verbose})
defer done()

funcs, err := client.List(context.Background(), c.Namespace)
if err != nil {
return fmt.Errorf("failed to list functions: %w", err)
}

if len(funcs) == 0 {
return errors.New("no functions found to describe")
}

names := []string{}
for _, f := range funcs {
names = append(names, f.Name)
}

prompt := &survey.Select{
Message: "Select a function to describe:",
Options: names,
}

var selected string
if err := survey.AskOne(prompt, &selected); err != nil {
return err
}

c.Name = selected
return nil
}


// Output Formatting (serializers)
// -------------------------------

Expand Down
Loading