Python Forum
i want to make a cli command that ...
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i want to make a cli command that ...
#4
(Sep-28-2017, 05:39 PM)nilamo Wrote: If you want to do it, then it doesn't matter whether or not I do it, right?  Because you'd still end up doing it yourself anyway :p
perhaps.

(Sep-28-2017, 06:02 PM)nilamo Wrote:
import sys


def get_buffer_size():
buffer_size = 1
if len(sys.argv) > 1:
buffer_size = abs(int(sys.argv[1]))
return buffer_size


def consume_input(buffer_size):
buffer =
head_sent = False
for line in sys.stdin:
buffer.append(line)
if len(buffer) > buffer_size:
if not head_sent:
head_sent = True
for line in buffer:
print(line, end="")
buffer =
else:
buffer.pop(0)

if head_sent and buffer:
print("-" * 78)
for line in buffer:
print(line, end="")


if __name__ == "__main__":
try:
buffer_size = get_buffer_size()
consume_input(buffer_size)
except ValueError as err:
print("Invalid buffer size. Any argument to this script should be a number.")
Output:
E:\Projects\etc>pip help | headtail.py Usage: ------------------------------------------------------------------------------ download. Implied with --no-index. E:\Projects\etc>pip help | headtail.py -4 Usage: pip <command> [options] Commands: ------------------------------------------------------------------------------ --disable-pip-version-check Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
off by one: i'm getting 1 more line than specified for the head

it looks like quoting source code loses indents.

perhaps i would code it anyway.  coding is fun.  but for headtail, i just want to have the tool.

i guess i will code one of my own to have something in a free license i can give away in a "collection of POSIX commands done in Python" unless nilamo puts his own in such a license (BSD, MIT, GPL, etc.).
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Messages In This Thread
i want to make a cli command that ... - by Skaperen - Sep-28-2017, 03:44 AM
RE: i want to make a cli command that ... - by Skaperen - Sep-29-2017, 05:16 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  i need to make a command that ... Skaperen 5 2,982 Nov-30-2019, 09:20 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020