Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add an option to change default cli prompt #114

Closed
laixintao opened this issue Aug 26, 2019 · 12 comments · Fixed by #441
Closed

Add an option to change default cli prompt #114

laixintao opened this issue Aug 26, 2019 · 12 comments · Fixed by #441

Comments

@laixintao
Copy link
Owner

See the discussion here:

http://redisdoc.com/transaction/exec.html#comment-4588712198

https://stackoverflow.com/questions/52690515/change-redis-command-prompt-text/52691005

@guoweikuang
Copy link
Contributor

I don't think it's necessary, so I can know more clearly that I am currently on the redis server.

@laixintao
Copy link
Owner Author

@guoweikuang Yes normally you don't need this, only if you want to make the prompt shorter on purpose.

For example, your redis domain name is too long.

When you do this, like --prompt={host} (yes, wen can let user setting it with python's template), I think you already know what you are doing.

@laixintao
Copy link
Owner Author

The usage like this:

$ iredis --prompt='{host[:10]}'  # set hostname max length is 10

$ iredis --prompt='{host[:10]:{port}[{db}]'

$ iredis --prompt='{port}' # only show port on prompt

@laixintao
Copy link
Owner Author

Client source port is supported.

@laixintao
Copy link
Owner Author

laixintao commented Jan 9, 2020

connection id;
client name;

@laixintao
Copy link
Owner Author

server cluster name;
server role(master/slave)

@aymericbeaumet
Copy link
Contributor

I'm embedding iredis into an in-house CLI for our engineering team, and the --prompt flag could come handy (supported by some other tools like https://github.com/dbcli/pgcli).

Would you accept a PR in that direction?

@laixintao
Copy link
Owner Author

laixintao commented Jul 22, 2022

@aymericbeaumet sure thing. Is #114 (comment) looks good to you?

and what placeholders do you want?
currently what I can come with are:

  • host
  • port
  • db number
  • client id?
  • client port?
  • current username used to auth?

any others?

@aymericbeaumet
Copy link
Contributor

aymericbeaumet commented Jul 23, 2022

@aymericbeaumet sure thing. Is #114 (comment) looks good to you?

Yes, that should be doable using some kind of template engine (I'm not a Python developer).

currently what I can come with are:

Yes that looks good. Nothing else comes to mind atm. I guess it will be easy to add once we get the basic structure in place.

@aymericbeaumet
Copy link
Contributor

@laixintao ready for review: #437

@laixintao
Copy link
Owner Author

@aymericbeaumet iredis 1.12.1 released, enjoy.
https://github.com/laixintao/iredis/releases/tag/v1.12.1

FYI, documentation updated:

Change The Default Prompt

You can change the prompt str, the default prompt is:

127.0.0.1:6379>

Which is rendered by {host}:{port}[{db}]> , you can change this via --prompt option or change
iredisrc
config file. The prompwt string uses python string format engine, supported
interpolations:

  • {client_name}
  • {db}
  • {host}
  • {path}
  • {port}
  • {username}
  • {client_addr}
  • {client_id}

The --prompt utilize
Python String format engine,
so as long as it is a valid string formatter, it will work( anything that
"<your prompt>".format(...) accepts). For example, you can limit your Redis
server host name's length to 5 by setting --prompt to
iredis --prompt '{host:.5s}'.

@aymericbeaumet
Copy link
Contributor

@laixintao Great work thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants