lisette-stdlib 0.1.13

Little language inspired by Rust that compiles to Go
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
// Generated by Lisette bindgen
// Source: flag (Go stdlib)
// Go: 1.25.5
// Lisette: 0.1.12

import "go:encoding"
import "go:io"
import "go:time"

/// Arg returns the i'th command-line argument. Arg(0) is the first remaining argument
/// after flags have been processed. Arg returns an empty string if the
/// requested element does not exist.
pub fn Arg(i: int) -> string

/// Args returns the non-flag command-line arguments.
pub fn Args() -> Slice<string>

/// Bool defines a bool flag with specified name, default value, and usage string.
/// The return value is the address of a bool variable that stores the value of the flag.
pub fn Bool(name: string, value: bool, usage: string) -> Ref<bool>

/// BoolFunc defines a flag with the specified name and usage string without requiring values.
/// Each time the flag is seen, fn is called with the value of the flag.
/// If fn returns a non-nil error, it will be treated as a flag value parsing error.
pub fn BoolFunc(
  name: string,
  usage: string,
  fn_: fn(string) -> Result<(), error>,
)

/// BoolVar defines a bool flag with specified name, default value, and usage string.
/// The argument p points to a bool variable in which to store the value of the flag.
pub fn BoolVar(p: Ref<bool>, name: string, value: bool, usage: string)

/// Duration defines a time.Duration flag with specified name, default value, and usage string.
/// The return value is the address of a time.Duration variable that stores the value of the flag.
/// The flag accepts a value acceptable to time.ParseDuration.
pub fn Duration(name: string, value: time.Duration, usage: string) -> Ref<time.Duration>

/// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
/// The argument p points to a time.Duration variable in which to store the value of the flag.
/// The flag accepts a value acceptable to time.ParseDuration.
pub fn DurationVar(
  p: Ref<time.Duration>,
  name: string,
  value: time.Duration,
  usage: string,
)

/// Float64 defines a float64 flag with specified name, default value, and usage string.
/// The return value is the address of a float64 variable that stores the value of the flag.
pub fn Float64(name: string, value: float64, usage: string) -> Ref<float64>

/// Float64Var defines a float64 flag with specified name, default value, and usage string.
/// The argument p points to a float64 variable in which to store the value of the flag.
pub fn Float64Var(p: Ref<float64>, name: string, value: float64, usage: string)

/// Func defines a flag with the specified name and usage string.
/// Each time the flag is seen, fn is called with the value of the flag.
/// If fn returns a non-nil error, it will be treated as a flag value parsing error.
pub fn Func(name: string, usage: string, fn_: fn(string) -> Result<(), error>)

/// Int defines an int flag with specified name, default value, and usage string.
/// The return value is the address of an int variable that stores the value of the flag.
pub fn Int(name: string, value: int, usage: string) -> Ref<int>

/// Int64 defines an int64 flag with specified name, default value, and usage string.
/// The return value is the address of an int64 variable that stores the value of the flag.
pub fn Int64(name: string, value: int64, usage: string) -> Ref<int64>

/// Int64Var defines an int64 flag with specified name, default value, and usage string.
/// The argument p points to an int64 variable in which to store the value of the flag.
pub fn Int64Var(p: Ref<int64>, name: string, value: int64, usage: string)

/// IntVar defines an int flag with specified name, default value, and usage string.
/// The argument p points to an int variable in which to store the value of the flag.
pub fn IntVar(p: Ref<int>, name: string, value: int, usage: string)

pub fn Lookup(name: string) -> Option<Ref<Flag>>

/// NArg is the number of arguments remaining after flags have been processed.
pub fn NArg() -> int

/// NFlag returns the number of command-line flags that have been set.
pub fn NFlag() -> int

pub fn NewFlagSet(name: string, errorHandling: ErrorHandling) -> Ref<FlagSet>

/// Parse parses the command-line flags from [os.Args][1:]. Must be called
/// after all flags are defined and before flags are accessed by the program.
pub fn Parse()

/// Parsed reports whether the command-line flags have been parsed.
pub fn Parsed() -> bool

/// PrintDefaults prints, to standard error unless configured otherwise,
/// a usage message showing the default settings of all defined
/// command-line flags.
/// For an integer valued flag x, the default output has the form
/// 
/// 	-x int
/// 		usage-message-for-x (default 7)
/// 
/// The usage message will appear on a separate line for anything but
/// a bool flag with a one-byte name. For bool flags, the type is
/// omitted and if the flag name is one byte the usage message appears
/// on the same line. The parenthetical default is omitted if the
/// default is the zero value for the type. The listed type, here int,
/// can be changed by placing a back-quoted name in the flag's usage
/// string; the first such item in the message is taken to be a parameter
/// name to show in the message and the back quotes are stripped from
/// the message when displayed. For instance, given
/// 
/// 	flag.String("I", "", "search `directory` for include files")
/// 
/// the output will be
/// 
/// 	-I directory
/// 		search directory for include files.
/// 
/// To change the destination for flag messages, call [CommandLine].SetOutput.
pub fn PrintDefaults()

/// Set sets the value of the named command-line flag.
pub fn Set(name: string, value: string) -> Result<(), error>

/// String defines a string flag with specified name, default value, and usage string.
/// The return value is the address of a string variable that stores the value of the flag.
pub fn String(name: string, value: string, usage: string) -> Ref<string>

/// StringVar defines a string flag with specified name, default value, and usage string.
/// The argument p points to a string variable in which to store the value of the flag.
pub fn StringVar(p: Ref<string>, name: string, value: string, usage: string)

/// TextVar defines a flag with a specified name, default value, and usage string.
/// The argument p must be a pointer to a variable that will hold the value
/// of the flag, and p must implement encoding.TextUnmarshaler.
/// If the flag is used, the flag value will be passed to p's UnmarshalText method.
/// The type of the default value must be the same as the type of p.
pub fn TextVar(
  p: encoding.TextUnmarshaler,
  name: string,
  value: encoding.TextMarshaler,
  usage: string,
)

/// Uint defines a uint flag with specified name, default value, and usage string.
/// The return value is the address of a uint variable that stores the value of the flag.
pub fn Uint(name: string, value: uint, usage: string) -> Ref<uint>

/// Uint64 defines a uint64 flag with specified name, default value, and usage string.
/// The return value is the address of a uint64 variable that stores the value of the flag.
pub fn Uint64(name: string, value: uint64, usage: string) -> Ref<uint64>

/// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
/// The argument p points to a uint64 variable in which to store the value of the flag.
pub fn Uint64Var(p: Ref<uint64>, name: string, value: uint64, usage: string)

/// UintVar defines a uint flag with specified name, default value, and usage string.
/// The argument p points to a uint variable in which to store the value of the flag.
pub fn UintVar(p: Ref<uint>, name: string, value: uint, usage: string)

/// UnquoteUsage extracts a back-quoted name from the usage
/// string for a flag and returns it and the un-quoted usage.
/// Given "a `name` to show" it returns ("name", "a name to show").
/// If there are no back quotes, the name is an educated guess of the
/// type of the flag's value, or the empty string if the flag is boolean.
pub fn UnquoteUsage(flag: Ref<Flag>) -> (string, string)

/// Var defines a flag with the specified name and usage string. The type and
/// value of the flag are represented by the first argument, of type [Value], which
/// typically holds a user-defined implementation of [Value]. For instance, the
/// caller could create a flag that turns a comma-separated string into a slice
/// of strings by giving the slice the methods of [Value]; in particular, [Set] would
/// decompose the comma-separated string into the slice.
pub fn Var(value: Value, name: string, usage: string)

/// Visit visits the command-line flags in lexicographical order, calling fn
/// for each. It visits only those flags that have been set.
pub fn Visit(fn_: fn(Ref<Flag>) -> ())

/// VisitAll visits the command-line flags in lexicographical order, calling
/// fn for each. It visits all flags, even those not set.
pub fn VisitAll(fn_: fn(Ref<Flag>) -> ())

/// ErrorHandling defines how [FlagSet.Parse] behaves if the parse fails.
pub struct ErrorHandling(int)

/// A Flag represents the state of a flag.
pub struct Flag {
  pub Name: string,
  pub Usage: string,
  pub Value: Option<Value>,
  pub DefValue: string,
}

/// A FlagSet represents a set of defined flags. The zero value of a FlagSet
/// has no name and has [ContinueOnError] error handling.
/// 
/// [Flag] names must be unique within a FlagSet. An attempt to define a flag whose
/// name is already in use will cause a panic.
pub struct FlagSet {
  pub Usage: fn() -> (),
}

/// Getter is an interface that allows the contents of a [Value] to be retrieved.
/// It wraps the [Value] interface, rather than being part of it, because it
/// appeared after Go 1 and its compatibility rules. All [Value] types provided
/// by this package satisfy the [Getter] interface, except the type used by [Func].
pub interface Getter {
  fn Get() -> Unknown
  fn Set(arg0: string) -> Result<(), error>
  fn String() -> string
}

/// Value is the interface to the dynamic value stored in a flag.
/// (The default value is represented as a string.)
/// 
/// If a Value has an IsBoolFlag() bool method returning true,
/// the command-line parser makes -name equivalent to -name=true
/// rather than using the next command-line argument.
/// 
/// Set is called once, in command line order, for each flag present.
/// The flag package may call the [String] method with a zero-valued receiver,
/// such as a nil pointer.
pub interface Value {
  fn Set(arg0: string) -> Result<(), error>
  fn String() -> string
}

const ContinueOnError: ErrorHandling = 0

const ExitOnError: ErrorHandling = 1

const PanicOnError: ErrorHandling = 2

pub var CommandLine: Ref<FlagSet>

/// ErrHelp is the error returned if the -help or -h flag is invoked
/// but no such flag is defined.
pub var ErrHelp: error

/// Usage prints a usage message documenting all defined command-line flags
/// to [CommandLine]'s output, which by default is [os.Stderr].
/// It is called when an error occurs while parsing flags.
/// The function is a variable that may be changed to point to a custom function.
/// By default it prints a simple header and calls [PrintDefaults]; for details about the
/// format of the output and how to control it, see the documentation for [PrintDefaults].
/// Custom usage functions may choose to exit the program; by default exiting
/// happens anyway as the command line's error handling strategy is set to
/// [ExitOnError].
pub var Usage: fn() -> ()

impl FlagSet {
  /// Arg returns the i'th argument. Arg(0) is the first remaining argument
  /// after flags have been processed. Arg returns an empty string if the
  /// requested element does not exist.
  fn Arg(self: Ref<FlagSet>, i: int) -> string

  /// Args returns the non-flag arguments.
  fn Args(self: Ref<FlagSet>) -> Slice<string>

  /// Bool defines a bool flag with specified name, default value, and usage string.
  /// The return value is the address of a bool variable that stores the value of the flag.
  fn Bool(self: Ref<FlagSet>, name: string, value: bool, usage: string) -> Ref<bool>

  /// BoolFunc defines a flag with the specified name and usage string without requiring values.
  /// Each time the flag is seen, fn is called with the value of the flag.
  /// If fn returns a non-nil error, it will be treated as a flag value parsing error.
  fn BoolFunc(
    self: Ref<FlagSet>,
    name: string,
    usage: string,
    fn_: fn(string) -> Result<(), error>,
  )

  /// BoolVar defines a bool flag with specified name, default value, and usage string.
  /// The argument p points to a bool variable in which to store the value of the flag.
  fn BoolVar(
    self: Ref<FlagSet>,
    p: Ref<bool>,
    name: string,
    value: bool,
    usage: string,
  )

  /// Duration defines a time.Duration flag with specified name, default value, and usage string.
  /// The return value is the address of a time.Duration variable that stores the value of the flag.
  /// The flag accepts a value acceptable to time.ParseDuration.
  fn Duration(
    self: Ref<FlagSet>,
    name: string,
    value: time.Duration,
    usage: string,
  ) -> Ref<time.Duration>

  /// DurationVar defines a time.Duration flag with specified name, default value, and usage string.
  /// The argument p points to a time.Duration variable in which to store the value of the flag.
  /// The flag accepts a value acceptable to time.ParseDuration.
  fn DurationVar(
    self: Ref<FlagSet>,
    p: Ref<time.Duration>,
    name: string,
    value: time.Duration,
    usage: string,
  )

  /// ErrorHandling returns the error handling behavior of the flag set.
  fn ErrorHandling(self: Ref<FlagSet>) -> ErrorHandling

  /// Float64 defines a float64 flag with specified name, default value, and usage string.
  /// The return value is the address of a float64 variable that stores the value of the flag.
  fn Float64(self: Ref<FlagSet>, name: string, value: float64, usage: string) -> Ref<float64>

  /// Float64Var defines a float64 flag with specified name, default value, and usage string.
  /// The argument p points to a float64 variable in which to store the value of the flag.
  fn Float64Var(
    self: Ref<FlagSet>,
    p: Ref<float64>,
    name: string,
    value: float64,
    usage: string,
  )

  /// Func defines a flag with the specified name and usage string.
  /// Each time the flag is seen, fn is called with the value of the flag.
  /// If fn returns a non-nil error, it will be treated as a flag value parsing error.
  fn Func(
    self: Ref<FlagSet>,
    name: string,
    usage: string,
    fn_: fn(string) -> Result<(), error>,
  )

  /// Init sets the name and error handling property for a flag set.
  /// By default, the zero [FlagSet] uses an empty name and the
  /// [ContinueOnError] error handling policy.
  fn Init(self: Ref<FlagSet>, name: string, errorHandling: ErrorHandling)

  /// Int defines an int flag with specified name, default value, and usage string.
  /// The return value is the address of an int variable that stores the value of the flag.
  fn Int(self: Ref<FlagSet>, name: string, value: int, usage: string) -> Ref<int>

  /// Int64 defines an int64 flag with specified name, default value, and usage string.
  /// The return value is the address of an int64 variable that stores the value of the flag.
  fn Int64(self: Ref<FlagSet>, name: string, value: int64, usage: string) -> Ref<int64>

  /// Int64Var defines an int64 flag with specified name, default value, and usage string.
  /// The argument p points to an int64 variable in which to store the value of the flag.
  fn Int64Var(
    self: Ref<FlagSet>,
    p: Ref<int64>,
    name: string,
    value: int64,
    usage: string,
  )

  /// IntVar defines an int flag with specified name, default value, and usage string.
  /// The argument p points to an int variable in which to store the value of the flag.
  fn IntVar(
    self: Ref<FlagSet>,
    p: Ref<int>,
    name: string,
    value: int,
    usage: string,
  )

  /// Lookup returns the [Flag] structure of the named flag, returning nil if none exists.
  fn Lookup(self: Ref<FlagSet>, name: string) -> Option<Ref<Flag>>

  /// NArg is the number of arguments remaining after flags have been processed.
  fn NArg(self: Ref<FlagSet>) -> int

  /// NFlag returns the number of flags that have been set.
  fn NFlag(self: Ref<FlagSet>) -> int

  /// Name returns the name of the flag set.
  fn Name(self: Ref<FlagSet>) -> string

  /// Output returns the destination for usage and error messages. [os.Stderr] is returned if
  /// output was not set or was set to nil.
  fn Output(self: Ref<FlagSet>) -> io.Writer

  /// Parse parses flag definitions from the argument list, which should not
  /// include the command name. Must be called after all flags in the [FlagSet]
  /// are defined and before flags are accessed by the program.
  /// The return value will be [ErrHelp] if -help or -h were set but not defined.
  fn Parse(self: Ref<FlagSet>, arguments: Slice<string>) -> Result<(), error>

  /// Parsed reports whether f.Parse has been called.
  fn Parsed(self: Ref<FlagSet>) -> bool

  /// PrintDefaults prints, to standard error unless configured otherwise, the
  /// default values of all defined command-line flags in the set. See the
  /// documentation for the global function PrintDefaults for more information.
  fn PrintDefaults(self: Ref<FlagSet>)

  /// Set sets the value of the named flag.
  fn Set(self: Ref<FlagSet>, name: string, value: string) -> Result<(), error>

  /// SetOutput sets the destination for usage and error messages.
  /// If output is nil, [os.Stderr] is used.
  fn SetOutput(self: Ref<FlagSet>, output: io.Writer)

  /// String defines a string flag with specified name, default value, and usage string.
  /// The return value is the address of a string variable that stores the value of the flag.
  fn String(self: Ref<FlagSet>, name: string, value: string, usage: string) -> Ref<string>

  /// StringVar defines a string flag with specified name, default value, and usage string.
  /// The argument p points to a string variable in which to store the value of the flag.
  fn StringVar(
    self: Ref<FlagSet>,
    p: Ref<string>,
    name: string,
    value: string,
    usage: string,
  )

  /// TextVar defines a flag with a specified name, default value, and usage string.
  /// The argument p must be a pointer to a variable that will hold the value
  /// of the flag, and p must implement encoding.TextUnmarshaler.
  /// If the flag is used, the flag value will be passed to p's UnmarshalText method.
  /// The type of the default value must be the same as the type of p.
  fn TextVar(
    self: Ref<FlagSet>,
    p: encoding.TextUnmarshaler,
    name: string,
    value: encoding.TextMarshaler,
    usage: string,
  )

  /// Uint defines a uint flag with specified name, default value, and usage string.
  /// The return value is the address of a uint variable that stores the value of the flag.
  fn Uint(self: Ref<FlagSet>, name: string, value: uint, usage: string) -> Ref<uint>

  /// Uint64 defines a uint64 flag with specified name, default value, and usage string.
  /// The return value is the address of a uint64 variable that stores the value of the flag.
  fn Uint64(self: Ref<FlagSet>, name: string, value: uint64, usage: string) -> Ref<uint64>

  /// Uint64Var defines a uint64 flag with specified name, default value, and usage string.
  /// The argument p points to a uint64 variable in which to store the value of the flag.
  fn Uint64Var(
    self: Ref<FlagSet>,
    p: Ref<uint64>,
    name: string,
    value: uint64,
    usage: string,
  )

  /// UintVar defines a uint flag with specified name, default value, and usage string.
  /// The argument p points to a uint variable in which to store the value of the flag.
  fn UintVar(
    self: Ref<FlagSet>,
    p: Ref<uint>,
    name: string,
    value: uint,
    usage: string,
  )

  /// Var defines a flag with the specified name and usage string. The type and
  /// value of the flag are represented by the first argument, of type [Value], which
  /// typically holds a user-defined implementation of [Value]. For instance, the
  /// caller could create a flag that turns a comma-separated string into a slice
  /// of strings by giving the slice the methods of [Value]; in particular, [Set] would
  /// decompose the comma-separated string into the slice.
  fn Var(self: Ref<FlagSet>, value: Value, name: string, usage: string)

  /// Visit visits the flags in lexicographical order, calling fn for each.
  /// It visits only those flags that have been set.
  fn Visit(self: Ref<FlagSet>, fn_: fn(Ref<Flag>) -> ())

  /// VisitAll visits the flags in lexicographical order, calling fn for each.
  /// It visits all flags, even those not set.
  fn VisitAll(self: Ref<FlagSet>, fn_: fn(Ref<Flag>) -> ())
}