# How to implement command which will appear in config and show?

**URL:** https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266
**Category:** YANG
**Created:** [February 3, 2019, 5:01pm UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266 "2019-02-03T17:01:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![darktime](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@darktime](https://dmap-community.ductus.global/u/darktime)
#### Post date: [February 3, 2019, 5:01pm UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/1 "2019-02-03T17:01:10Z")

</div>

I want to add my feature, which will should include both config and show commands. I think that you need to create the main container “my\_feature” which consist of 2 containers: the first container “conf\_feature” and the second “show\_feature”. For example:

> ```
> container my_feature {
> container conf_feature {
> tailf:cli-drop-node-name;
> tailf:info commands my_feature;
> tailf:cli-add-mode;
> leaf something_conf_1 {}
> leaf something_conf_2{}
> }
> container show_feature {
> config false;
> tailf:info show my_feature information;
> tailf:cli-drop-node-name;
> tailf:callpoint show_feature;
> container interface {
> list brief {}
> list detail {}
> }
> container other_info {}
> }
> }
> 
> ```

I want to enter command $ show my\_feature, and invoke callback function for display my\_feature summary information. I don`t understand how to implement.  
Also I enter command $ show my\_feature interface, Confd makes a call to a function callback for 2 branches of the brief and details at once, what do you need to specify so that by default it does only for the brief?

---

<div class="post-metadata">

### Author: ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)
#### Post date: [February 6, 2019, 1:37pm UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/2 "2019-02-06T13:37:32Z")

</div>

In case you need specializedoutpu in CLI, you can use custom `clispec` comand for operational mode. In callback of this `clispec` you can call regular CLI via maapi. E.g. `clispec` command `show my_feature interface` would call in callback `maapi_cli_cmd` with string parameter `"show my_feature interface brief"`. See `clispec` section in ConfD User guide and `confd_lib_maapi` - command `maapi_cli_cmd`.

---

<div class="post-metadata">

### Author: ![darktime](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@darktime](https://dmap-community.ductus.global/u/darktime)
#### Post date: [February 13, 2019, 1:46pm UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/3 "2019-02-13T13:46:50Z")

</div>

> [@mnovak](#):
>
> In case you need specializedoutpu in CLI, you can use custom `clispec` comand for operational mode. In callback of this `clispec` you can call regular CLI via maapi. E.g. `clispec` command `show my_feature interface` would call in callback `maapi_cli_cmd` with string parameter `"show my_feature interface brief"` . See `clispec` section in ConfD User guide and `confd_lib_maapi` - command `maapi_cli_cmd` .

Hi mnovak, thnx for this answer. I read user guide Confd to chapters cli and maapi. I don’t need specializedoutput in CLI. I tried create 2 sub-modules. The first submodule consist of config parameters and it have main container “my\_feature”. I create the second submodule which import the first submodule also augment “/my\_feature” and consist of operational data. It’s working. I have problem. Custom help texts is shown both in config and show modes because it add in container “my\_feature” in tailf:info Config commands my\_feature. How to implement other text in show mode?

---

<div class="post-metadata">

### Author: ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)
#### Post date: [February 15, 2019, 11:42am UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/4 "2019-02-15T11:42:08Z")

</div>

Hello,

> [@darktime](#):
>
> I don’t need specializedoutput in CLI.

OK, from description:

_Confd makes a call to a function callback for 2 branches of the brief and details at once, what do you need to specify so that by default it does only for the brief?_

U thought you need special CLI behavior (i.e. make `show my_feature interface` behave as `show my_feature interface brief`), which could be achieved with `clispec`.

> [@darktime](#):
>
> I tried create 2 sub-modules. The first submodule consist of config parameters and it have main container “my\_feature”. I create the second submodule which import the first submodule also augment “/my\_feature” and consist of operational data. It’s working. I have problem. Custom help texts is shown both in config and show modes because it add in container “my\_feature” in tailf:info Config commands my\_feature. How to implement other text in show mode?

By _“2 sub-modules”_ , do you mean YANG submodules (`submodule` statment) or something elese? I’m not fully sure what kid of reuse do you try to achieve. maybe `grouping` statement can help here. Please, paste example.

---

<div class="post-metadata">

### Author: ![darktime](https://avatars.discourse-cdn.com/v4/letter/d/e56c9b/32.png) [@darktime](https://dmap-community.ductus.global/u/darktime)
#### Post date: [February 18, 2019, 8:51am UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/5 "2019-02-18T08:51:30Z")

</div>

```auto
submodule my_feature_conf 
{

	belong-to main_yang { prefix main_yang; }
	import tailf-common { prefix tailf; }

grouping MyFeatureGlobalCommands{
    	leaf Set1{
        	type Set1;
        	tailf:info "Set 1";
    	}
    	leaf Set2{
        	type Set2;
        	tailf:info "Set 2;
    	}
        }
        uses MyFeatureCommonCommands;
    }
}

	container my_feature{
    	tailf:info "My_feature commands";
    	tailf:cli-add-mode;
    	uses MyFeatureGlobalCommands;
	}
}

/ *******************my_feature-show-command************************************ /

submodule my_feature_show
{
	belong-to main_yang { prefix main_yang; }
	import tailf-common { prefix tailf; }	
	import ietf-inet-types { prefix inet; }

	include my_feature_conf; 	

	grouping my_feature_session_brief
{
          list brief
        {
            tailf:info "Show my_feature session brief format";
            tailf:cli-show-template-enter "";
            tailf:cli-show-template-footer "\n";
            tailf:cli-table-legend "Flags: Legend information\n" ;    
            tailf:cli-full-show-path { tailf:cli-max-keys 1; }
            tailf:cli-enforce-table;
            tailf:sort-order unsorted;
            key "interface destination source";
            leaf interface { type string; }
            leaf destination { type inet:ipv4-address; }   
            leaf source { type inet:ipv4-address; }
            leaf type { type session_type; }
            leaf owner { type string; }
        }
}
grouping my_feature_session_detail
{
     list detail
     {
        tailf:info "Show my_feature session detail format";
        tailf:cli-full-show-path { tailf:cli-max-keys 1; }
        tailf:cli-suppress-table;
        tailf:cli-show-template-enter "";
        tailf:cli-show-template-footer "\n";
        tailf:cli-show-template-legend "Flags: Legend information\n";
        tailf:cli-show-template "\n"
    + "Interface $(interface)\n"
    + "Source address: $(src_address)\n"
    + "Destination address: $(dst_address)\n"
    + "State: $(state)\n"
    + "...........AND SO ON..........................";
        tailf:sort-order unsorted;
        key "interface src_address dst_address";
        leaf interface { type string; }
        leaf src_address { type inet:ipv4-address; }
        leaf dst_address { type inet:ipv4-address; }
        leaf state { type session_type; }
        /*.............AND SO ON................*/
     }
} 
grouping my_feature_show_session {
    container session {
        tailf:info "Show my_feature session information";
        config false;        
        uses my_feature_session_brief;
        uses my_feature_session_detail;
    }
}

	grouping MyFeatureShowData {

    container my_feature_show{
        tailf:cli-drop-node-name;
        tailf:info "Show my_feature information";
        tailf:callpoint MyFeatureShow {}
        config false;
        list client {
            tailf:info "Show my_feature client information";
                tailf:sort-order unsorted;
                key "name state";
                leaf name { type string; }
                leaf state { type string; }
                leaf num-sessions { type uint32; }
                uses my_feature_show_summary;
                uses my_feature_show_session;
                uses my_feature_show_neighbor;
                uses my_feature_show_counters;
                uses my_feature_show_interface;
        }
        uses my_feature_show_summary;
        uses my_feature_show_session;
        uses my_feature_show_neighbor;
        uses my_feature_show_counters;
        uses my_feature_show_interface;
    }
}
augment "/my_feature" { uses MyFeatureShowData;}
}

```

I pasted example.

> [@mnovak](#):
>
> U thought you need special CLI behavior (i.e. make `show my_feature interface` behave as `show my_feature interface brief` ), which could be achieved with `clispec` .

If I got it right, I need do this command move src=“my\_feature interface” dest=“my\_feature interface brief”

I have question in my example. In grouping session has 2 list brief and detail. How to describe lists, that I could to will request both list with check key? For example:

`$ show my_feature session brief`

Confd check key “interface src\_address dst\_address”, and call get\_object list brief.

`$show my_feature session detail`

Confd check key “interface src\_address dst\_address”, and call get\_object list brief and list detail.

---

<div class="post-metadata">

### Author: ![mnovak](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/mnovak/32/183_2.png) [@mnovak](https://dmap-community.ductus.global/u/mnovak)
#### Post date: [February 18, 2019, 11:10am UTC](https://dmap-community.ductus.global/t/how-to-implement-command-which-will-appear-in-config-and-show/2266/6 "2019-02-18T11:10:10Z")

</div>

> [@darktime](#):
>
> If I got it right, I need do this command move src=“my\_feature interface” dest=“my\_feature interface brief”

I meant something like this:

```auto
<?xml version="1.0" encoding="UTF-8"?><clispec xmlns="http://tail-f.com/ns/clispec/1.0" style="c">
  <operationalMode>
    <cmd name="my_feature" mount="show">            
      <cmd name="interface">                
	<callback>
          <capi>
             <cmdpoint>show_my_feature_interface</cmdpoint>                        
	  </capi>
	</callback>
      </cmd>
   </cmd>
 </operationalMode>
</clispec>

```

Then in callpoint (in C application) you can call `maapi_cli_cmd("show my_feature interface brief")`, so everytime you issue `show my_feature interface` it will be redirected to `show my_feature interface brief`.

> [@](#):
>
> Custom help texts is shown both in config and show modes because it add in container “my\_feature” in tailf:info Config commands my\_feature. How to implement other text in show mode

Do you mean `tailf:info "My_feature commands";` under `my_feature` container? In case you mix operational and config data (commands), I think you need to choose `info` statement that can be applied to both modes (as you datamodel is part of both modes). This `info` seems applicable for both modes.

> [@](#):
>
> `$ show my_feature session brief`  
> Confd check key “interface src\_address dst\_address”, and call get\_object list brief.  
> `$show my_feature session detail`  
> Confd check key “interface src\_address dst\_address”, and call get\_object list brief and list detail.

What would be the purpose of calling `get_object` for `brief` if you are in `detail` list? Do you have some reuse in mind? If so, in C callback you can implement reuse in C (just extract common parts to some function). E.g. reuse to get key element values (as they are same for both - `brief` and `detail`).
