Coder Social home page Coder Social logo

Comments (3)

vogxn avatar vogxn commented on May 24, 2024 1

I've taken the above mentioned approach and reduced the clutter in the completer.py module. There is now a parser.py (complementing a lexer.py) that reads the entire command set into a tree rooted at kubectl. Given a command line, we walk the nodes of this tree as far as we can and return the children of the last node in the path as suggestions to fuzzyfinder.

TODO:

  • finish the global options parsing at any level of the subcommand
  • complete the get_resource(..) calls given a localFlag is used.

from kube-shell.

vogxn avatar vogxn commented on May 24, 2024

Ran into a bunch of troubles doing this. My initial idea was to read the command tree into a nested set of parsers created using argparse. However, argparse is not tolerant if parts of the command line don't adhere to the command tree it holds. It does a hard os.exit() which is problematic.

Going to switch back to a simple object tree representation. We will walk the tree and identify the extent of the traversal until tokens on command line are identified. The children of the node we reach point to the list of possible suggestions.

// CommandTree represents the Node (command) and its children (subcommands/options)
type CommandTree struct {
    Node string,
    Children []CommandTree
}

func Walk(t *CommandTree, parsed []string, unparsed []string) (suggestions []string) {
    token = unparsed.Pop()   // get first token
    if t.Node == token {
       parsed = append(parsed, token)
       for _, child := range(t.Children) {
            // walk all children with rest of the tokens
            Walk(child, parsed, unparsed)
       }
    } else {
        if len(unparsed) > 0 {
            suggestions := make([]string)
            for _, suggestion := range(t.Children) {
                   suggestions = append(suggestions, suggestion)
            }
            return  // suggestions come from children
        }
    }
}

from kube-shell.

murali-reddy avatar murali-reddy commented on May 24, 2024

In case any one wants try out please check this branch

from kube-shell.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.