cybertrain 0.2.0 → 0.3.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.
@@ -0,0 +1,36 @@
1
+ module Cybertrain
2
+ # The one definition of "a name usable as the application's package name":
3
+ # `cybertrain build`/`server` (CLI::Build.app_name, reading spin.toml) and
4
+ # the development rebuilder (Dev::Rebuilder.new, which shells out with the
5
+ # name Application.new(name:) was given) both ask here, so the rules
6
+ # cannot drift apart. Application.new itself does not: production never
7
+ # builds. A leaf file with no requires: the CLI (CRuby) and the framework
8
+ # (Spinel) both load it. String methods only, no Regexp, because it
9
+ # compiles under Spinel (see Dev::Rebuilder).
10
+ module AppName
11
+ # "" when name works as a `spin build` target and as the build/bin/<name>
12
+ # path, else the reason (a String on every path, NOTES rules 10/34).
13
+ # Shell safety is not this method's job: both callers quote the name when
14
+ # they build a command ("my-app" and "MyApp" are fine for `spin build`),
15
+ # so only what breaks the target or the path is refused.
16
+ def self.problem(name)
17
+ # An empty name would become an explicit "" argument to spin.
18
+ return "cannot be empty" if name.empty?
19
+ # "." and ".." name build/bin/. and build/bin/.., which exist already
20
+ # (the latter is build/) and only fail later, in assemble's cp.
21
+ return "cannot be '.' or '..'" if name == "." || name == ".."
22
+ # Quoting leaves a leading "-" bare ("-" is in quote_arg's safe set),
23
+ # and even quoted `spin build '-x'` is parsed by spin as an option, not
24
+ # as the package name. Whether spin accepts `--` before the target is
25
+ # unverified, hence a refusal.
26
+ return "cannot start with '-' (spin would read it as an option)" if name.start_with?("-")
27
+ # A "/" would put the binary in a subdirectory of build/bin.
28
+ return "cannot contain '/'" if name.include?("/")
29
+ # Whitespace splits the target in the places that do not quote it, and
30
+ # a newline ends a command line.
31
+ return "cannot contain whitespace" if name.include?(" ") || name.include?("\t") || name.include?("\n") || name.include?("\r")
32
+
33
+ ""
34
+ end
35
+ end
36
+ end