-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
60f950b
commit b6f2ab5
Showing
11 changed files
with
214 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import click | ||
import inspect | ||
from composio.cli.context import Context, pass_context | ||
from composio.client import Composio | ||
from click.formatting import HelpFormatter | ||
from composio.exceptions import ComposioSDKError | ||
from composio.utils.url import get_web_url | ||
|
||
from click.core import Context as ClickContext | ||
|
||
class HelpfulCmdBase: | ||
examples = [] | ||
|
||
def format_help_text(self, ctx: ClickContext, formatter: HelpFormatter) -> None: | ||
"""Writes the help text to the formatter if it exists.""" | ||
if self.help is not None: | ||
# truncate the help text to the first form feed | ||
text = inspect.cleandoc(self.help).partition("\f")[0] | ||
else: | ||
text = "" | ||
|
||
text = "📄" + text | ||
if getattr(self, 'deprecated', False): | ||
text = "(Deprecated) {text}".format(text=text) | ||
|
||
if text: | ||
formatter.write_paragraph() | ||
formatter.write_text(click.style(text, fg='white')) | ||
|
||
def format_options(self, ctx: ClickContext, formatter: HelpFormatter) -> None: | ||
"""Writes all the options into the formatter if they exist.""" | ||
opts = [] | ||
for param in self.get_params(ctx): | ||
rv = param.get_help_record(ctx) | ||
if rv is not None: | ||
if '-h' in rv[0] or '-help' in rv[0] or '--help' in rv[0]: | ||
continue | ||
opts.append(rv) | ||
|
||
if opts: | ||
formatter.write(" 🔗 Options \n\n") | ||
formatter.write_dl(opts) | ||
|
||
def format_examples(self, ctx, formatter): | ||
formatter.write("\n📙 Examples:\n\n") | ||
for example in self.examples: | ||
formatter.write(example) | ||
|
||
def format_help(self, ctx, formatter): | ||
formatter.write("\n") | ||
self.format_help_text(ctx, formatter) | ||
formatter.write("\n") | ||
self.format_options(ctx, formatter) | ||
self.format_examples(ctx, formatter) | ||
|
||
|
||
class HelpfulCmd(HelpfulCmdBase, click.Command): | ||
examples = [ | ||
click.style("composio login", fg='green') + click.style(" # Login with browser support\n", fg='black'), | ||
click.style("composio login --no-browser", fg='green') + click.style(" # Login without browser interaction\n", fg='black'), | ||
] | ||
|
||
|
||
class HelpfulGroup(HelpfulCmdBase, click.Group): | ||
pass |
Oops, something went wrong.