@@ -25,18 +25,21 @@ defmodule System do
25
25
@ doc """
26
26
Returns Elixir's version as binary.
27
27
"""
28
+ @ spec version ( ) :: String . t
28
29
def version , do: "0.7.2.dev"
29
30
30
31
@ doc """
31
32
Returns a keywords list with version, git tag info and date.
32
33
"""
34
+ @ spec build_info ( ) :: Keyword . t
33
35
def build_info do
34
36
[ version: version , tag: get_describe , date: get_date ]
35
37
end
36
38
37
39
@ doc """
38
40
Returns the list of command-line arguments passed to the program.
39
41
"""
42
+ @ spec argv ( ) :: [ String . t ]
40
43
def argv do
41
44
:gen_server . call ( :elixir_code_server , :argv )
42
45
end
@@ -61,6 +64,8 @@ defmodule System do
61
64
If `command` is a char list, a char list is returned.
62
65
Returns a binary otherwise.
63
66
"""
67
+ @ spec cmd ( char_list ) :: char_list
68
+ @ spec cmd ( String . t ) :: String . t
64
69
def cmd ( command ) when is_list ( command ) do
65
70
:os . cmd ( command )
66
71
end
@@ -77,6 +82,8 @@ defmodule System do
77
82
If `command` is a char list, a char list is returned.
78
83
Returns a binary otherwise.
79
84
"""
85
+ @ spec find_executable ( char_list ) :: char_list | nil
86
+ @ spec find_executable ( String . t ) :: String . t | nil
80
87
def find_executable ( command ) when is_list ( command ) do
81
88
:os . find_executable ( command ) || nil
82
89
end
@@ -93,6 +100,7 @@ defmodule System do
93
100
given as a single string of the format "VarName=Value", where VarName is the
94
101
name of the variable and Value its value.
95
102
"""
103
+ @ spec get_env ( ) :: [ { String . t , String . t } ]
96
104
def get_env do
97
105
Enum . map :os . getenv , :unicode . characters_to_binary & 1
98
106
end
@@ -102,6 +110,7 @@ defmodule System do
102
110
`varname` as a binary, or nil if the environment
103
111
variable is undefined.
104
112
"""
113
+ @ spec get_env ( String . t ) :: String . t | nil
105
114
def get_env ( varname ) do
106
115
case :os . getenv ( to_char_list ( varname ) ) do
107
116
false -> nil
@@ -115,19 +124,23 @@ defmodule System do
115
124
116
125
See http://www.erlang.org/doc/man/os.html#getpid-0 for more info.
117
126
"""
127
+ @ spec get_pid ( ) :: String . t
118
128
def get_pid , do: list_to_binary ( :os . getpid )
119
129
120
130
@ doc """
121
131
Sets a new `value` for the environment variable `varname`.
122
132
"""
133
+ @ spec put_env ( String . t , String . t | char_list ) :: :ok
123
134
def put_env ( varname , value ) when is_binary ( value ) or is_list ( value ) do
124
135
:os . putenv to_char_list ( varname ) , :unicode . characters_to_list ( value )
136
+ :ok
125
137
end
126
138
127
139
@ doc """
128
140
Sets a new value for each environment variable corresponding
129
141
to each key in `dict`.
130
142
"""
143
+ @ spec put_env ( Dict . t ) :: :ok
131
144
def put_env ( dict ) do
132
145
Enum . each dict , fn { key , val } -> put_env key , val end
133
146
end
0 commit comments