Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

No way to make the value of an option optional

Đang mở
#69 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
55/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
lua
Lĩnh vực
cli

Hướng nghiên cứu

Bắt đầu với khai báo tùy chọn và các lời gọi parsing được thể hiện trong optopt.lua, đặc biệt là cli:option("-f, --foo=[VALUE]", ...) và cli:parse(_G.arg). Theo dõi cách một tùy chọn không được cung cấp giá trị được xử lý, sau đó xác minh rằng một flag bị bỏ qua, một -f đứng riêng và -f buz tạo ra ba kết quả được mô tả trong issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

In the 2.x series of releases it was possible to setup an option that had no value if not set, a default value if just the flag was added but no value given, and additionally a custom value if a value was passed. In 3.x this does not seem to be possible. Flags cannot take values and options always require a value. The default for options is only parsed in the event the option flag is not even passed.

As an example, I would like the value of a --foo=[VALUE] option to be optional with a default value if set, but allow the user to set (or not set) foo. If this is optopt.lua:

#!/usr/bin/env lua

local cli = require("cliargs")

cli:set_name("optopt")
cli:set_description("optional arg test")
cli:option("-f, --foo=[VALUE]", "foo val default to fiz", "fiz")
cli:flag("-h, --help", "display this help, then exit")

local opts, err = cli:parse(_G.arg)

if not opts and err then
  print(err)
  os.exit(1)
end

print("foo is", opts.foo)

What I get vs. what I expect:

# as expected
$ ./optopt.lua -f buz
foo is  buz

# unexpected, no option should mean no value
$ ./optopt.lua
foo is  fiz

# unexpected, setting the option should enable the default value if no value passed
$ ./optopt.lua -f
option -f requires a value to be set
Ngôn ngữ chính
Lua
Star
129
Fork
26
Merge trung bình
1 giờ 41 phút
Pull request đã merge (30 ngày)
1

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của lunarmodules/lua_cliargs

Tất cả issue của lunarmodules/lua_cliargs

Issue tương tự

Thêm issue về Lua

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.