Changeset fc52ce1c8e051b2acc414eb64b229b43f8329b20

Show
Ignore:
Timestamp:
03/13/09 14:52:58 (6 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1236955978 +0000
git-parent:

[56c7e9dd00981d9018a28e7adf1fb6144821c51e]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1236955978 +0000
Message:

more complete tab completion, refs #37

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_check.c

    r56c7e9d rfc52ce1  
    858858} 
    859859 
     860char * 
     861noit_console_conf_check_opts(noit_console_closure_t ncct, 
     862                             noit_console_state_stack_t *stack, 
     863                             noit_console_state_t *dstate, 
     864                             int argc, char **argv, int idx) { 
     865  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     866  uuid_t key_id; 
     867  int klen, i = 0; 
     868  noit_check_t *check; 
     869 
     870  if(argc == 1) { 
     871    if(!strncmp("new", argv[0], strlen(argv[0]))) { 
     872      if(idx == i) return strdup("new"); 
     873      i++; 
     874    } 
     875    while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 
     876                         (void **)&check)) { 
     877      char out[512]; 
     878      char uuid_str[37]; 
     879      snprintf(out, sizeof(out), "%s`%s", check->target, check->name); 
     880      uuid_unparse_lower(check->checkid, uuid_str); 
     881      if(!strncmp(out, argv[0], strlen(argv[0]))) { 
     882        if(idx == i) return strdup(out); 
     883        i++; 
     884      } 
     885      if(!strncmp(uuid_str, argv[0], strlen(argv[0]))) { 
     886        if(idx == i) return strdup(uuid_str); 
     887        i++; 
     888      } 
     889    } 
     890  } 
     891  if(argc == 2) { 
     892    cmd_info_t *cmd; 
     893    if(!strcmp("new", argv[0])) return NULL; 
     894    cmd = noit_skiplist_find(&dstate->cmds, "attribute", NULL); 
     895    if(!cmd) return NULL; 
     896    return noit_console_opt_delegate(ncct, stack, cmd->dstate, argc-1, argv+1, idx); 
     897  } 
     898  return NULL; 
     899} 
     900 
     901char * 
     902noit_console_check_opts(noit_console_closure_t ncct, 
     903                        noit_console_state_stack_t *stack, 
     904                        noit_console_state_t *dstate, 
     905                        int argc, char **argv, int idx) { 
     906  noit_hash_iter iter = NOIT_HASH_ITER_ZERO; 
     907  uuid_t key_id; 
     908  int klen, i = 0; 
     909  noit_check_t *check; 
     910 
     911  if(argc == 1) { 
     912    while(noit_hash_next(&polls, &iter, (const char **)key_id, &klen, 
     913                         (void **)&check)) { 
     914      char out[512]; 
     915      char uuid_str[37]; 
     916      snprintf(out, sizeof(out), "%s`%s", check->target, check->name); 
     917      uuid_unparse_lower(check->checkid, uuid_str); 
     918      if(!strncmp(out, argv[0], strlen(argv[0]))) { 
     919        if(idx == i) return strdup(out); 
     920        i++; 
     921      } 
     922      if(!strncmp(uuid_str, argv[0], strlen(argv[0]))) { 
     923        if(idx == i) return strdup(uuid_str); 
     924        i++; 
     925      } 
     926    } 
     927  } 
     928  if(argc == 2) { 
     929    return noit_console_opt_delegate(ncct, stack, dstate, argc-1, argv+1, idx); 
     930  } 
     931  return NULL; 
     932} 
     933 
    860934static int 
    861935noit_console_show_checks(noit_console_closure_t ncct, 
  • src/noit_check.h

    r84d6f13 rfc52ce1  
    203203API_EXPORT(void) noit_check_log_metrics(noit_check_t *check); 
    204204 
     205API_EXPORT(char *) 
     206  noit_console_check_opts(noit_console_closure_t ncct, 
     207                          noit_console_state_stack_t *stack, 
     208                          noit_console_state_t *dstate, 
     209                          int argc, char **argv, int idx); 
     210API_EXPORT(char *) 
     211  noit_console_conf_check_opts(noit_console_closure_t ncct, 
     212                               noit_console_state_stack_t *stack, 
     213                               noit_console_state_t *dstate, 
     214                               int argc, char **argv, int idx); 
     215 
    205216#endif 
  • src/noit_conf_checks.c

    r56c7e9d rfc52ce1  
    223223  return rv; 
    224224} 
     225 
    225226static int 
    226227noit_console_check(noit_console_closure_t ncct, 
     
    13211322 
    13221323  NEW_STATE(_unset_state); 
    1323   DELEGATE_CMD(_unset_state, "attribute", noit_console_opt_delegate, _uattr_state); 
    1324   ADD_CMD(_unset_state, "section", noit_console_config_section, NULL, NULL, (void *)1); 
    1325   ADD_CMD(_unset_state, "config", noit_console_config_unsetconfig, NULL, NULL, NULL); 
    1326   ADD_CMD(_unset_state, "check", noit_console_config_nocheck, NULL, NULL, NULL); 
     1324  DELEGATE_CMD(_unset_state, "attribute", 
     1325               noit_console_opt_delegate, _uattr_state); 
     1326  ADD_CMD(_unset_state, "section", 
     1327          noit_console_config_section, NULL, NULL, (void *)1); 
     1328  ADD_CMD(_unset_state, "config", 
     1329          noit_console_config_unsetconfig, NULL, NULL, NULL); 
     1330  ADD_CMD(_unset_state, "check", 
     1331          noit_console_config_nocheck, NULL, NULL, NULL); 
    13271332  
    13281333  NEW_STATE(_conf_t_check_state); 
    13291334  _conf_t_check_state->console_prompt_function = conf_t_check_prompt; 
    1330   DELEGATE_CMD(_conf_t_check_state, "attribute", noit_console_opt_delegate, _attr_state); 
    1331   DELEGATE_CMD(_conf_t_check_state, "no", noit_console_opt_delegate, _unset_state); 
    1332   ADD_CMD(_conf_t_check_state, "config", noit_console_config_setconfig, NULL, NULL, NULL); 
    1333   ADD_CMD(_conf_t_check_state, "status", noit_console_show_check, NULL, NULL, NULL); 
    1334   ADD_CMD(_conf_t_check_state, "exit", noit_console_config_cd, NULL, NULL, ".."); 
    1335   ADD_CMD(_conf_t_check_state, "check", noit_console_check, NULL, _conf_t_check_state, ".."); 
     1335  DELEGATE_CMD(_conf_t_check_state, "attribute", 
     1336               noit_console_opt_delegate, _attr_state); 
     1337  DELEGATE_CMD(_conf_t_check_state, "no", 
     1338               noit_console_opt_delegate, _unset_state); 
     1339  ADD_CMD(_conf_t_check_state, "config", 
     1340          noit_console_config_setconfig, NULL, NULL, NULL); 
     1341  ADD_CMD(_conf_t_check_state, "status", 
     1342          noit_console_show_check, NULL, NULL, NULL); 
     1343  ADD_CMD(_conf_t_check_state, "exit", 
     1344          noit_console_config_cd, NULL, NULL, ".."); 
     1345  ADD_CMD(_conf_t_check_state, "check", 
     1346          noit_console_check, noit_console_conf_check_opts, 
     1347          _conf_t_check_state, ".."); 
    13361348 
    13371349  NEW_STATE(_conf_t_state);  
     
    13401352  ADD_CMD(_conf_t_state, "ls", noit_console_config_show, NULL, NULL, NULL); 
    13411353  ADD_CMD(_conf_t_state, "cd", noit_console_config_cd, NULL, NULL, NULL); 
    1342   ADD_CMD(_conf_t_state, "config", noit_console_config_setconfig, NULL, NULL, NULL); 
    1343   ADD_CMD(_conf_t_state, "section", noit_console_config_section, NULL, NULL, (void *)0); 
    1344   ADD_CMD(_conf_t_state, "check", noit_console_check, NULL, _conf_t_check_state, NULL); 
     1354  ADD_CMD(_conf_t_state, "config", 
     1355          noit_console_config_setconfig, NULL, NULL, NULL); 
     1356  ADD_CMD(_conf_t_state, "section", 
     1357          noit_console_config_section, NULL, NULL, (void *)0); 
     1358  ADD_CMD(_conf_t_state, "check", 
     1359          noit_console_check, noit_console_conf_check_opts, 
     1360          _conf_t_check_state, NULL); 
    13451361 
    13461362  showcmd = noit_console_state_get_cmd(tl, "show"); 
    1347   ADD_CMD(showcmd->dstate, "check", noit_console_show_check, NULL, NULL, NULL); 
    1348  
    1349   ADD_CMD(tl, "watch", noit_console_watch_check, NULL, NULL, (void *)1); 
     1363  ADD_CMD(showcmd->dstate, "check", 
     1364          noit_console_show_check, noit_console_check_opts, NULL, NULL); 
     1365 
     1366  ADD_CMD(tl, "watch", 
     1367          noit_console_watch_check, noit_console_check_opts, NULL, (void *)1); 
    13501368 
    13511369  nocmd = noit_console_state_get_cmd(tl, "no"); 
    1352   ADD_CMD(nocmd->dstate, "watch", noit_console_watch_check, NULL, NULL, (void *)0); 
    1353  
    1354   DELEGATE_CMD(_conf_t_state, "write", noit_console_opt_delegate, _write_state); 
    1355   DELEGATE_CMD(_conf_t_state, "attribute", noit_console_opt_delegate, _attr_state); 
     1370  ADD_CMD(nocmd->dstate, "watch", 
     1371          noit_console_watch_check, noit_console_check_opts, NULL, (void *)0); 
     1372 
     1373  DELEGATE_CMD(_conf_t_state, "write", 
     1374               noit_console_opt_delegate, _write_state); 
     1375  DELEGATE_CMD(_conf_t_state, "attribute", 
     1376               noit_console_opt_delegate, _attr_state); 
    13561377  DELEGATE_CMD(_conf_t_state, "no", noit_console_opt_delegate, _unset_state); 
    13571378 
    13581379  NEW_STATE(_conf_state); 
    1359   ADD_CMD(_conf_state, "terminal", noit_console_state_conf_terminal, NULL, _conf_t_state, NULL); 
    1360  
    1361   ADD_CMD(tl, "configure", noit_console_state_delegate, noit_console_opt_delegate, _conf_state, NULL); 
    1362   ADD_CMD(tl, "write", noit_console_state_delegate, noit_console_opt_delegate, _write_state, NULL); 
     1380  ADD_CMD(_conf_state, "terminal", 
     1381          noit_console_state_conf_terminal, NULL, _conf_t_state, NULL); 
     1382 
     1383  ADD_CMD(tl, "configure", 
     1384          noit_console_state_delegate, noit_console_opt_delegate, 
     1385          _conf_state, NULL); 
     1386  ADD_CMD(tl, "write", 
     1387          noit_console_state_delegate, noit_console_opt_delegate, 
     1388          _write_state, NULL); 
    13631389  ADD_CMD(tl, "reload", noit_conf_checks_reload, NULL, NULL, NULL); 
    13641390} 
  • src/noit_console_complete.c

    r56c7e9d rfc52ce1  
    2626                          int idx) { 
    2727  int i; 
    28   noit_skiplist_node *next
     28  noit_skiplist_node *next, *curr
    2929  cmd_info_t *cmd; 
    3030 
     
    4141 
    4242  cmd = noit_skiplist_find_neighbors(&state->cmds, argv[0], 
    43                                      NULL, NULL, &next); 
     43                                     NULL, &curr, &next); 
    4444  if(cmd) { 
    45     if(argc == 1) { 
    46       if(idx == 0) return strdup(cmd->name); 
    47       return NULL; 
    48     } 
    49     if(!cmd->autocomplete) return NULL; 
    50     return cmd->autocomplete(ncct, stack, cmd->dstate, argc-1, argv+1, idx); 
    51   } 
    52  
     45    if(argc != 1) { 
     46      if(!cmd->autocomplete) return NULL; 
     47      return cmd->autocomplete(ncct, stack, cmd->dstate, argc-1, argv+1, idx); 
     48    } 
     49    next = curr; 
     50    goto multiples; 
     51  } 
     52 
     53 multiples: 
    5354  if(!next) return NULL; 
    5455  i = 0; 
    5556  while(next) { 
    5657    cmd = next->data; 
    57     if(strncasecmp(cmd->name, argv[0], strlen(argv[0])) == 0) 
     58    if(strncasecmp(cmd->name, argv[0], strlen(argv[0])) == 0) { 
    5859      if(idx == i) return strdup(cmd->name); 
    59     i++; 
     60      i++; 
     61    } 
    6062    noit_skiplist_next(&state->cmds, &next); 
    6163  } 
     
    178180unsigned char 
    179181noit_edit_complete(EditLine *el, int invoking_key) { 
    180   static const char *rl_basic_word_break_characters = " \t\n\"\\'`@$><=;|&{("; 
     182  static const char *rl_basic_word_break_characters = " \t\n\"\\'@$><=;|&{("; 
    181183  static const char *rl_special_prefixes = NULL; 
    182184  static const int   rl_completion_append_character = ' ';