telethon 0.4.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/README.md +34 -62
- data/lib/telethon/cli/args.rb +33 -0
- data/lib/telethon/cli/call.rb +182 -0
- data/lib/telethon/cli/commands/account.rb +357 -0
- data/lib/telethon/cli/commands/bots.rb +91 -0
- data/lib/telethon/cli/commands/chats.rb +279 -0
- data/lib/telethon/cli/commands/reading.rb +203 -0
- data/lib/telethon/cli/commands/writing.rb +278 -0
- data/lib/telethon/cli/commands.rb +158 -468
- data/lib/telethon/cli/completion.rb +100 -0
- data/lib/telethon/cli/table.rb +805 -0
- data/lib/telethon/cli.rb +108 -45
- data/lib/telethon/client/auth.rb +12 -4
- data/lib/telethon/client/files.rb +11 -5
- data/lib/telethon/client/messages.rb +82 -13
- data/lib/telethon/custom/dialog.rb +5 -0
- data/lib/telethon/network/sender.rb +22 -1
- data/lib/telethon/network/transport.rb +14 -1
- data/lib/telethon/private_files.rb +5 -1
- data/lib/telethon/version.rb +1 -1
- data/lib/telethon.rb +8 -0
- metadata +9 -1
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Telethon
|
|
4
|
+
module CLI
|
|
5
|
+
# Generates bash, zsh, and fish completion scripts directly from Telethon::CLI::Table.
|
|
6
|
+
module Completion
|
|
7
|
+
SHELLS = %w[bash zsh fish].freeze
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def generate(shell)
|
|
12
|
+
case shell
|
|
13
|
+
when "bash" then bash
|
|
14
|
+
when "zsh" then zsh
|
|
15
|
+
when "fish" then fish
|
|
16
|
+
else raise UsageError, "unsupported shell #{shell.inspect} (expected bash, zsh, or fish)"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def bash
|
|
21
|
+
cmds = (Table.names + %w[help --help --version]).join(" ")
|
|
22
|
+
cases = Table::COMMANDS.map do |entry|
|
|
23
|
+
opts = entry[:spec].keys.join(" ")
|
|
24
|
+
" #{entry[:name]}) COMPREPLY=( $(compgen -W \"#{opts}\" -- \"$cur\") ) ;;"
|
|
25
|
+
end.join("\n")
|
|
26
|
+
<<~SH
|
|
27
|
+
# bash completion for tg (generated by `tg completion bash`)
|
|
28
|
+
_tg_completions() {
|
|
29
|
+
local cur="${COMP_WORDS[COMP_CWORD]}"
|
|
30
|
+
local cmd="${COMP_WORDS[1]}"
|
|
31
|
+
if [[ ${COMP_CWORD} -eq 1 ]]; then
|
|
32
|
+
COMPREPLY=( $(compgen -W "#{cmds}" -- "$cur") )
|
|
33
|
+
return 0
|
|
34
|
+
fi
|
|
35
|
+
if [[ "$cmd" == "help" ]]; then
|
|
36
|
+
COMPREPLY=( $(compgen -W "#{Table.names.join(' ')}" -- "$cur") )
|
|
37
|
+
return 0
|
|
38
|
+
fi
|
|
39
|
+
case "$cmd" in
|
|
40
|
+
#{cases}
|
|
41
|
+
esac
|
|
42
|
+
}
|
|
43
|
+
complete -F _tg_completions tg
|
|
44
|
+
SH
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def zsh
|
|
48
|
+
desc_lines = Table::COMMANDS.map do |entry|
|
|
49
|
+
" '#{entry[:name]}:#{escape_single(entry[:summary])}'"
|
|
50
|
+
end
|
|
51
|
+
desc_lines << " 'help:show help for a command'"
|
|
52
|
+
cases = Table::COMMANDS.map do |entry|
|
|
53
|
+
opt_args = entry[:options].map do |flag, desc|
|
|
54
|
+
spec = entry[:spec][flag]
|
|
55
|
+
suffix = spec == :flag ? "" : ":value:"
|
|
56
|
+
"'#{flag}[#{escape_single(desc)}]#{suffix}'"
|
|
57
|
+
end.join(" ")
|
|
58
|
+
" #{entry[:name]}) _arguments #{opt_args} ;;"
|
|
59
|
+
end.join("\n")
|
|
60
|
+
<<~SH
|
|
61
|
+
#compdef tg
|
|
62
|
+
# zsh completion for tg (generated by `tg completion zsh`)
|
|
63
|
+
_tg() {
|
|
64
|
+
local -a commands
|
|
65
|
+
commands=(
|
|
66
|
+
#{desc_lines.join("\n")}
|
|
67
|
+
)
|
|
68
|
+
if (( CURRENT == 2 )); then
|
|
69
|
+
_describe 'command' commands
|
|
70
|
+
return
|
|
71
|
+
fi
|
|
72
|
+
case "$words[2]" in
|
|
73
|
+
#{cases}
|
|
74
|
+
help) _describe 'command' commands ;;
|
|
75
|
+
esac
|
|
76
|
+
}
|
|
77
|
+
compdef _tg tg
|
|
78
|
+
SH
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def fish
|
|
82
|
+
lines = ["# fish completion for tg (generated by `tg completion fish`)"]
|
|
83
|
+
Table::COMMANDS.each do |entry|
|
|
84
|
+
lines << "complete -c tg -n '__fish_use_subcommand' -a '#{entry[:name]}' -d '#{escape_single(entry[:summary])}'"
|
|
85
|
+
entry[:options].each do |flag, desc|
|
|
86
|
+
long = flag.delete_prefix("--")
|
|
87
|
+
req = entry[:spec][flag] == :flag ? "" : " -r"
|
|
88
|
+
lines << "complete -c tg -n '__fish_seen_subcommand_from #{entry[:name]}' -l '#{long}'#{req} -d '#{escape_single(desc)}'"
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
lines << "complete -c tg -n '__fish_use_subcommand' -a 'help' -d 'show help for a command'"
|
|
92
|
+
"#{lines.join("\n")}\n"
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def escape_single(text)
|
|
96
|
+
text.to_s.gsub("'", "'\\\\''")
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|