Transforms commands to a normalized `Navigation`
332938
function computeNavigation(commands) {
    if ((typeof commands[0] === 'string') && commands.length === 1 && commands[0] === '/') {
        return new Navigation(true, 0, commands);
    }
    var numberOfDoubleDots = 0;
    var isAbsolute = false;
    var res = commands.reduce(function (res, cmd, cmdIdx) {
        if (typeof cmd === 'object' && cmd != null) {
            if (cmd.outlets) {
                var outlets_1 = {};
                forEach(cmd.outlets, function (commands, name) {
                    outlets_1[name] = typeof commands === 'string' ? commands.split('/') : commands;
                });
                return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spread"])(res, [{ outlets: outlets_1 }]);
            }
            if (cmd.segmentPath) {
                return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spread"])(res, [cmd.segmentPath]);
            }
        }
        if (!(typeof cmd === 'string')) {
            return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spread"])(res, [cmd]);
        }
        if (cmdIdx === 0) {
            cmd.split('/').forEach(function (urlPart, partIndex) {
                if (partIndex == 0 && urlPart === '.') ;
                else if (partIndex == 0 && urlPart === '') { //  '/a'
                    isAbsolute = true;
                }
                else if (urlPart === '..') { //  '../a'
                    numberOfDoubleDots++;
                }
                else if (urlPart != '') {
                    res.push(urlPart);
                }
            });
            return res;
        }
        return Object(tslib__WEBPACK_IMPORTED_MODULE_0__["__spread"])(res, [cmd]);
    }, []);
    return new Navigation(isAbsolute, numberOfDoubleDots, res);
}
677246
def _click_resolve_command(root, parts):
    """"""
    location = root
    incomplete = ''
    for part in parts:
        incomplete = part

        if not part[0:2].isalnum():
            continue

        try:
            next_location = location.get_command(click.Context(location),
                                                 part)
            if next_location is not None:
                location = next_location
                incomplete = ''
        except AttributeError:
            break
    return location, incomplete
1321042
def _filter_commands(ctx, commands=None):
    """"""
    lookup = getattr(ctx.command, 'commands', {})
    if not lookup and isinstance(ctx.command, click.MultiCommand):
        lookup = _get_lazyload_commands(ctx.command)

    if commands is None:
        return sorted(lookup.values(), key=lambda item: item.name)

    names = [name.strip() for name in commands.split(',')]
    return [lookup[name] for name in names if name in lookup]
71824
function getSubCommands(context, command) {
  var commands = cli.getMapping(context).requisition.system.commands;
  var subcommands = commands.getAll().filter(function(subcommand) {
    return subcommand.name.indexOf(command.name) === 0 &&
           subcommand.name !== command.name &&
           !subcommand.hidden;
  });

  subcommands.sort(function(c1, c2) {
    return c1.name.localeCompare(c2.name);
  });

  subcommands = subcommands.map(function(subcommand) {
    return subcommand.toJson();
  });

  return subcommands;
}
1034854
def list_commands(self, ctx):
        """"""
        rv = []
        files = [_ for _ in next(os.walk(self.folder))[2] if not _.startswith("_") and _.endswith(".py")]
        for filename in files:
            rv.append(filename[:-3])
        rv.sort()
        return rv
1245919
def map_navigation(self):
        
        #All articles should have titles
        title_id = 'titlepage-{0}'.format(self.article_doi)
        title_label = self.article.publisher.nav_title()
        title_source = 'main.{0}.xhtml#title'.format(self.article_doi)
        title_navpoint = navpoint(title_id, title_label, self.play_order,
                                  title_source, [])
        self.nav.append(title_navpoint)
        #When processing a collection of articles, we will want all subsequent
        #navpoints for this article to be located under the title
        if self.collection:
            nav_insertion = title_navpoint.children
        else:
            nav_insertion = self.nav

        #If the article has a body, we'll need to parse it for navigation
        if self.article.body is not None:
            #Here is where we invoke the recursive parsing!
            for nav_pt in self.recursive_article_navmap(self.article.body):
                nav_insertion.append(nav_pt)

        #Add a navpoint to the references if appropriate
        if self.article.root.xpath('./back/ref'):
            ref_id = 'references-{0}'.format(self.article_doi)
            ref_label = 'References'
            ref_source = 'biblio.{0}.xhtml#references'.format(self.article_doi)
            ref_navpoint = navpoint(ref_id, ref_label, self.play_order,
                                    ref_source, [])
            nav_insertion.append(ref_navpoint)
492613
def _normalize_command_args(self, command, *args):
        
        if command == 'zadd' and not self.strict and len(args) >= 3:
            # Reorder score and name
            zadd_args = [x for tup in zip(args[2::2], args[1::2]) for x in tup]
            return [args[0]] + zadd_args

        if command in ('zrangebyscore', 'zrevrangebyscore'):
            # expected format is: <command> name min max start num with_scores score_cast_func
            if len(args) <= 3:
                # just plain min/max
                return args

            start, num = None, None
            withscores = False

            for i, arg in enumerate(args[3:], 3):
                # keywords are case-insensitive
                lower_arg = self._encode(arg).lower()

                # handle "limit"
                if lower_arg == b"limit" and i + 2 < len(args):
                    start, num = args[i + 1], args[i + 2]

                # handle "withscores"
                if lower_arg == b"withscores":
                    withscores = True

            # do not expect to set score_cast_func

            return args[:3] + (start, num, withscores)

        return args
281043
function normalizeActions(base, input) {
  if (!input) return;
  if (!Array.isArray(input)) input = [ input ];

  return flatten(input).filter(Boolean).map(function (action) {
    return normalizeAction(base, action);
  });
}
753254
function(dpad, normalize) {
        var x = 0,
            y = 0;

        // Sum up all active directions
        for (var d in dpad.directions) {
            var dir = dpad.directions[d];
            if (!dir.active) continue;
            x += dir.n.x;
            y += dir.n.y;
        }

        // Mitigate rounding errors when close to zero movement
        x = -1e-10 < x && x < 1e-10 ? 0 : x;
        y = -1e-10 < y && y < 1e-10 ? 0 : y;

        // Normalize
        if (normalize) {
            var m = Math.sqrt(x * x + y * y);
            if (m > 0) {
                x /= m;
                y /= m;
            }
        }

        dpad.x = x;
        dpad.y = y;
    }
11475
def reformat_cmd(self, text):
        
        # remove az if there
        text = text.replace('az', '')
        # disregard defaulting symbols
        if text and SELECT_SYMBOL['scope'] == text[0:2]:
            text = text.replace(SELECT_SYMBOL['scope'], "")

        if self.shell_ctx.default_command:
            text = self.shell_ctx.default_command + ' ' + text
        return text
791975
function flattenNavigation (nav, hasParent, flattened) {

    flattened = flattened || [];

    // loop through each navigation item
    for (var i = 0; i < nav.length; i++) {

        var _nav = utils.cloneWithout(nav[i], 'children');

        if (hasParent) {
            _nav.parent = hasParent;
        }

        flattened.push(_nav);

        if (nav[i].children) {
            flattened = flattenNavigation(nav[i].children, _nav, flattened);
        }

    }

    return flattened;

}
757338
def do_commander(self):
        """"""
        # Flatten commands list then extract primary command and its arguments.
        if self._args.commands is not None:
            cmds = []
            for cmd in self._args.commands:
                cmds.append(flatten_args(split_command_line(arg) for arg in cmd))
        else:
            cmds = None

        # Enter REPL.
        PyOCDCommander(self._args, cmds).run()
1136111
function commands(req, res /*, next */) {
  req.app.commands.forEach(function(command) {
    res.writeln(command);
  });
  res.end();
}
936173
function normalize(args) {
  let result = {
    queries:  null,
    callback: null
  };

  if (args.length === 1 && Array.isArray(args[0])) {
    result.queries = args[0];
  } else if (args.length === 2 && Array.isArray(args[0])) {
    result.queries = args[0];

    if (typeof args[1] === 'function') {
      result.callback = args[1];
    }
  } else {
    result.queries = args;

    if (typeof result.queries[result.queries.length - 1] === 'function') {
      result.callback = result.queries.pop();
    }
  }

  return result;
}
597375
function normalizeLinks(base, input) {
  if (!input) return;
  if (!Array.isArray(input)) input = [ input ];

  return flatten(input).filter(Boolean).map(function (link) {
    return normalizeLink(base, link);
  });
}
975342
function normalizeFns(fns) {
  Object.keys(fns).forEach(function(key) {
    var handler = fns[key];
    if (typeof handler === 'function') {
      fns[key] = {
        enter: handler,
        leave: noop
      };
    }
  });
}
541474
def replace_command(command, broken, matched):
    """"""
    new_cmds = get_close_matches(broken, matched, cutoff=0.1)
    return [replace_argument(command.script, broken, new_cmd.strip())
            for new_cmd in new_cmds]