import click
import os
from netifaces import interfaces, ifaddresses, AF_INET

@click.group()
def cli():
    pass

def get_env_vars(ctx, args, incomplete):
    return os.environ.keys()

@cli.command()
@click.argument("envvar", type=click.STRING, autocompletion=get_env_vars)
def cmd1(envvar):
    click.echo('Environment variable: %s' % envvar)
    click.echo('Value: %s' % os.environ[envvar])

@cli.command()
def cmd3():
    pass

@click.group()
def group():
    pass

def ip4_addresses():
    ip_list = []
    for interface in interfaces():
        for link in ifaddresses(interface)[AF_INET]:
            ip_list.append(link['addr'])
    return ip_list

@group.command()
@click.argument("ip", type=click.STRING, autocompletion=ip4_addresses)
def subcmd(ip):
    click.echo('Chosen IP is %s' % color)

cli.add_command(group)

@@ -19,63 +19,8 @@
 t os
-%0Afrom netifaces import interfaces, ifaddresses, AF_INET
 %0A%0A@c
@@ -337,45 +337,8 @@
 %5D)%0A%0A
-@cli.command()%0Adef cmd3():%0A    pass%0A%0A
 @cli
@@ -379,170 +379,123 @@
 def 
-ip4_addres
+list_u
 se
+r
 s(
-):%0A    ip_list = %5B%5D%0A    for interface in interfaces():%0A        for link in ifaddresses(interface)%5BAF_INET%5D:%0A            ip_list.append(link%5B'addr
+ctx, args, incomplete):%0A    # Here you can generate completions dynamically%0A    users = %5B'bob', 'alice
 '%5D
-)
 %0A   
@@ -506,15 +506,13 @@
 urn 
-ip_list
+users
 %0A%0A@g
@@ -543,18 +543,20 @@
 gument(%22
-ip
+user
 %22, type=
@@ -588,20 +588,17 @@
 ion=
-ip4_addres
+list_u
 se
+r
 s)%0Ad
@@ -611,10 +611,12 @@
 cmd(
-ip
+user
 ):%0A 
@@ -641,10 +641,12 @@
 sen 
-IP
+user
  is 
@@ -655,12 +655,11 @@
 ' %25 
-colo
+use
 r)%0A%0A

Update completion example